If you want to learn from scratch Docker, Take a look at this series of articles !
https://www.cnblogs.com/poloyy/category/1870863.html
install Docker
Refer to my article directly :https://www.cnblogs.com/poloyy/p/13921450.html
download Jenkins Mirror image
Search for jenkins Mirror image
docker search jenkins
Focus on the first three
- The first is the official mirror image , But the version is old , Not recommended
- Although it's not the official mirror image , however jenkins The version of will follow jenkins The official version , That is to say, it will keep the mirror image down jenkins The version is the latest , recommend , I also use this
- The third image is Chinese jenkins Mirror image , But the mirror system is not familiar to us centos、ubuntu、Debian etc. , It is Alpine, It's not common to install dependent libraries , Not recommended
download jenkins Mirror image
docker pull jenkins/jenkins
This will download the latest version of jenkins Mirror image
View local image
docker images
establish Jenkins Containers
Create a directory under the host
Used to mount the directory
mkdir -p /var/jenkins_node
Give the mount directory the highest permission
Readable, writable, and executable
chmod -R 777 /var/jenkins_node
Create and launch jenkins Containers
- -d: Guardian mode
- -uroot: Use root Identity into the container , It is recommended to add , Avoid permission errors when executing certain commands in the container
- -p: host 80 Of the port mapping container 8080 port , Later visit jenkins Direct access to the host ip That's it , No need to add 8080 port
- -v: Directory mapping
- --name: Customize a container name
- Use the one recommended above jenkins/jenkins Mirror image
docker run -d -uroot -p 80:8080 --name jenkins1 -v /var/jenkins_node:/var/jenkins_home jenkins/jenkins
See if the container is running
docker ps
Get into jenkins Containers CLI Interface
docker exec -it -uroot jenkins1 bash
You can also specify root Identity into the container
Lead to
# Get the latest packages apt-get update # Upgrade installed packages apt-get upgrade # Install in advance , For the next configuration operation apt-get -y install gcc automake autoconf libtool make apt-get -y install make* apt-get -y install zlib* apt-get -y install openssl libssl-dev apt-get install sudo
install Python Environmental Science
download python
cd /usr/local/src wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz tar -zxvf Python-3.6.8.tgz mv Python-3.6.8 py3.6 cd py3.6
make Compilation and installation
stay /usr/local/src/py3.6 Execute the following command in the installation directory
./configure --prefix=/var/jenkins_home/py3.6 make && make install
Add soft link
add to python3 Soft link
ln -s /usr/local/src/py3.6/bin/python3.6 /usr/bin/python3
add to pip3 Soft link
ln -s /usr/local/src/py3.6/bin/pip3 /usr/bin/pip3
If you have some, just ignore it
verification python3 Environmental Science
knock python3 and pip3 The result of the figure below is normal
Install the library required for the project
First
Need to be in python The project generates a requirement.txt, The specific tutorial can be seen in
https://www.cnblogs.com/poloyy/p/13953232.html
then
- take requirement.txt Upload to the host
- Copy from host to container docker cp requirement.txt jenkins1:/usr/local/src
Finally, install the required libraries for the project
pip3 install -r requirements.txt
install Allure Environmental Science
Download from the official website allure package
https://github.com/allure-framework/allure2/releases
Just choose the latest version , Or pick your own version
Transfer the compressed package into the container
- First upload the package to the host
- Then copy from the host to the container
docker cp allure-commandline-2.13.6.zip jenkins1:/usr/local/src
Unzip the package
unzip allure-commandline-2.13.6.zip
Give the highest permission to all contents of the folder
mv allure-2.13.6 allure chmod -R 777 allure
To configure allure and py environment variable
cat >> /etc/profile << "EOF" export PATH=/usr/local/src/allure/bin:$PATH export PATH=/usr/local/src/py3.6/bin:$PATH EOF
Remember to return one by one , Copy and paste, or just copy and paste
Update environment variable configuration file
source /etc/profile
Verify environment variables
allure --version
python3 --version
To configure JDK environment variable
View the current system configured environment variables
export
Here you can see many environment variables that come with the container itself
- Jenkins Version of
- JDK Installation path for
To configure JDK environment variable
cat >> /etc/profile << "EOF" export PATH=$JAVA_HOME/bin:$PATH EOF
Update environment variable configuration file
source /etc/profile