1. Build os basic mirror
1) Make your own os mirror Dockerfile, note that the first letter "D" of the Dockerfile name must be capitalized, otherwise it will not be recognized when you build it
[root@k8s centos7.6]# cat Dockerfile #Basic Mirror Source, download centos:7.6.1810 in dockerhub beforehand FROM centos:7.6.1810 #Mirror Maintainer MAINTAINER zhaojiehe #Configure yum source RUN yum install wget -y&&rm -rf /etc/yum.repos.d/* && wget -O /etc/yum.repos.d/epel.repo \ http://mirrors.aliyun.com/repo/epel-7.repo&&wget -O /etc/yum.repos.d/CentOS7-Base-163.repo \ http://mirrors.163.com/.help/CentOS7-Base-163.repo #Install necessary packages RUN yum install vim iotop bc gcc gcc-c++ glibc glibc-devel pcre pcre-devel \ openssl openssl-devel zip unzip zlib-devel net-tools lrzsz tree ntpdate \ telnet lsof tcpdump wget libevent libevent-devel bc systemd-devel \ bash-completion traceroute -y
2) Build os basic mirror through Dockerfile
[root@k8s centos7.6]# docker build -t k8s.harbor.cn/base_application/centos:7.6-base .
3) View the centos base image built
[root@k8s centos7.6]# docker images | grep 7.6-base
2. Building jdk environment mirror
1) Prepare jdk environment package
[root@k8s jdk-base]# ll
2) Prepare environment variable profile to replace profile file in jdk container
[root@k8s jdk-base]# cat profile | tail -n3 export JAVA_HOME=/usr/local/src/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
3) production of Dockerfile by jdk
[root@k8s jdk-base]# cat Dockerfile #The base image is the centos image made above FROM k8s.harbor.cn/base_application/centos:7.6-base #Mirror Maintainer MAINTAINER zhaojiehe #Add a jdk package to the path specified by the container and the ADD command will automatically decompress the package ADD jdk-8u221-linux-x64.tar.gz /usr/local/src #Create jdk soft connections and java program soft connections RUN ln -sv /usr/local/src/jdk1.8.0_221 /usr/local/src/jdk && ln -sv /usr/local/src/jdk/bin/* /usr/bin/ #Add a locally configured profile environment variable file to the container ADD profile /etc/profile #Declare environment variables to make the java environment work ENV JAVA_HOME /usr/local/src/jdk ENV PATH $JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH ENV CLASSPATH $JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
4) Start building as a jdk image
[root@k8s jdk-base]# docker build -t k8s.harbor.cn/base_application/jdk:1.8.u221-base .
5) View the built jdk image
[root@k8s jdk-base]# docker images | grep jdk
3. Building a jenkins mirror
1) Following are the files for building a jenkins image
[root@k8s jenkins]# ll
2) Download the war package of the jenkins program and pre-pack the plugins plugin package to avoid jenkins starting to download the plugins too slowly
3) Default to google's update source, which will result in the inability to connect to foreign sources and make jenkins unable to start, so modify hudson's url to update source for Tsinghua University in China
[root@k8s jenkins]# cat hudson.model.UpdateCenter.xml <?xml version='1.1' encoding='UTF-8'?> <sites> <site> <id>default</id> <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/current/update-center.json</url> </site> </sites>
4) The startup script for jenkins, specifying the war package, maximum and minimum heap memory, webroot application directory, and port to listen on through java commands
[root@k8s jenkins]# cat jenkins_start.sh #!/bin/bash cd /apps/jenkins && java -server -Xms1024m -Xmx1024m -jar jenkins-2.190.3.war --webroot=/apps/jenkins/war_data --httpPort=8081
5) Make a Dockerfile image of jenkins
[root@k8s jenkins]# cat Dockerfile #Specify the base mirror for jdk FROM k8s.harbor.cn/base_application/jdk:1.8.u221-base #Mirror Maintainer MAINTAINER zhaojiehe #Local default is UTC time zone, set time zone to domestic Shanghai time zone RUN rm -f /etc/localtime && ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #Locally modified hudson files are placed in the jenkins container ahead of time ADD hudson.model.UpdateCenter.xml /root/.jenkins/ #The plug-ins needed by jenkins are put into the container ADD jenkins_plugins.tar.gz /root/.jenkins/ #jenkins-initiated war s are added to the container and the / apps/jenkins / file directory is automatically created without manual creation ADD jenkins-2.190.3.war /apps/jenkins/ #jenkins startup script added to container ADD jenkins_start.sh /usr/bin/ #Expose Jenkins'specified port 8081 expose 8081 #Execute the daemon script command for jenkins CMD ["/usr/bin/jenkins_start.sh"]
6) Building a mirror of jenkins
[root@k8s jenkins]# docker build -t k8s.harbor.cn/base_application/jenkins-base:v1 .
7) View the built jenkins mirror
[root@k8s jenkins]# docker images
4. Start jenkins container application by mirroring
1) Command to launch the jenkins container
[root@k8s jenkins]# docker run -d -p 8181:8081 k8s.harbor.cn/base_application/jenkins-base:v1
2) Check if the jenkins container is started
[root@k8s jenkins]# docker ps | grep jenkins
3) web-side page access, visible need container specified path to get initialization password to continue
4) Enter the container to find the initial password
[root@k8s jenkins]# docker exec -it fc20749e2450 bash
5) The two most important directories after jenkins start up, one is the web root application directory and the other is the jenkins data directory. It is recommended to map to NFS storage or secure storage device path in production
#webroot application directory [root@fc20749e2450 /]# ll apps/jenkins/war_data/
#Jenkins Data Save Directory
[root@fc20749e2450 ~]# ll /root/.jenkins/