私有仓库已经搭建好了,先讲解下环境
我的docker registry在mesos slave 上,也就是之前的
可以看到私有的仓库里面已经有了3个镜像,这次我们要使用jenkins这个镜像,这个镜像主要包含了JAVA环境和一个tomcat工程,工程的webapps下是没有东西的
现在我在私有仓库的机器上删除所有的镜像和容器
root@web2:/opt/dockerfiles# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
root@web2:/opt/dockerfiles# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
看看我的Dockerfile
root@web2:/opt/dockerfiles# pwd
/opt/dockerfiles
root@web2:/opt/dockerfiles# ls
Dockerfile jenkins.war
root@web2:/opt/dockerfiles# more Dockerfile
FROM 172.16.126.129/jenkins
MAINTAINER jastme
#RUN apt-get install sysstat -y
#
#RUN apt-get install -y build-essential
#
#RUN apt-get install -y software-properties-common
#
#RUN apt-get install -y byobu curl git htop man unzip vim wget
COPY jenkins.war /ywkj/tomcat/webapps/jenkins.war
ENV JAVA_HOME=/opt/jdk1.7
ENV CLASSPATH=.:/opt/jdk1.7/lib/dt.jar:/opt/jdk1.7/lib/tools.jar
ENV PATH $JAVA_HOME/bin:$CLASSPATH:$PATH
EXPOSE 8080
ENTRYPOINT /ywkj/tomcat/bin/startup.sh && tail -F /ywkj/tomcat/logs/catalina.out
开始构建镜像
我们构建一个REPOSITORY为jenkins tag为test的镜像
root@web2:/opt/dockerfiles# docker build -t="jenkins:test" .
Sending build context to Docker daemon 69.02 MB
Sending build context to Docker daemon
Step 0 : FROM 172.16.126.129/jenkins
Pulling repository 172.16.126.129/jenkins
0f90f20ed759: Download complete
58488e45273c: Download complete
25810b66099e: Download complete
6571ba684f54: Download complete
6ed49a73d8f0: Download complete
c53777cbfc31: Download complete
56465e1e45d2: Download complete
9525990c1a59: Download complete
4b16211c9344: Download complete
Status: Downloaded newer image for 172.16.126.129/jenkins:latest
---> 0f90f20ed759
Step 1 : MAINTAINER jastme
---> Running in 249047b08222
---> 83c9d1880cbf
Removing intermediate container 249047b08222
Step 2 : COPY jenkins.war /ywkj/tomcat/webapps/jenkins.war
---> 8ddb8a0d43d0
Removing intermediate container df861980347c
Step 3 : ENV JAVA_HOME /opt/jdk1.7
---> Running in 8d769e747d0f
---> 9612f02f92a0
Removing intermediate container 8d769e747d0f
Step 4 : ENV CLASSPATH .:/opt/jdk1.7/lib/dt.jar:/opt/jdk1.7/lib/tools.jar
---> Running in 5a7e0eb0589d
---> 5cbeba873965
Removing intermediate container 5a7e0eb0589d
Step 5 : ENV PATH $JAVA_HOME/bin:$CLASSPATH:$PATH
---> Running in df35ac988bd3
---> a2d882bbae0f
Removing intermediate container df35ac988bd3
Step 6 : EXPOSE 8080
---> Running in 0af2fd672296
---> 2074c2b72310
Removing intermediate container 0af2fd672296
Step 7 : ENTRYPOINT /ywkj/tomcat/bin/startup.sh && tail -F /ywkj/tomcat/logs/catalina.out
---> Running in 4115910e5c92
---> 285b7399d473
Removing intermediate container 4115910e5c92
Successfully built 285b7399d473
root@web2:/opt/dockerfiles# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
jenkins test 285b7399d473 22 seconds ago 720.1 MB
172.16.126.129/jenkins latest 0f90f20ed759 29 hours ago 651.1 MB
OK,已经构建好了,现在开始启动容器
root@web2:/opt/dockerfiles# docker run -d --restart=always -p 8080:8080 --name jenkins jenkins:test
9a563fb692b3d029c3e2dbdb201b8f2d7bba447525af5dbb24ed83e7fc4acbfd
root@web2:/opt/dockerfiles# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a563fb692b3 jenkins:test "/bin/sh -c '/ywkj/t 5 seconds ago Up 3 seconds 0.0.0.0:8080->8080/tcp jenkins
已经成功启动
使用WEB测试
root@web2:/opt/dockerfiles# docker logs 9a563fb692b3
Tomcat started.
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/7.0.65
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Oct 9 2015 08:36:58 UTC
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 7.0.65.0
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Linux
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 4.2.0-27-generic
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: /opt/jdk1.7/jre
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.7.0_67-b01
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /ywkj/tomcat
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /ywkj/tomcat
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.util.logging.config.file=/ywkj/tomcat/conf/logging.properties
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/ywkj/tomcat/endorsed
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/ywkj/tomcat
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/ywkj/tomcat
Nov 25, 2016 9:14:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.io.tmpdir=/ywkj/tomcat/temp
Nov 25, 2016 9:14:54 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Nov 25, 2016 9:14:55 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Nov 25, 2016 9:14:55 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Nov 25, 2016 9:14:55 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2592 ms
Nov 25, 2016 9:14:55 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Nov 25, 2016 9:14:55 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.65
Nov 25, 2016 9:14:55 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /ywkj/tomcat/webapps/jenkins.war
Nov 25, 2016 9:15:57 AM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jenkins home directory: /root/.jenkins found at: $user.home/.jenkins
Nov 25, 2016 9:15:59 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /ywkj/tomcat/webapps/jenkins.war has finished in 64,314 ms
Nov 25, 2016 9:15:59 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /ywkj/tomcat/webapps/manager
Nov 25, 2016 9:16:00 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /ywkj/tomcat/webapps/manager has finished in 393 ms
Nov 25, 2016 9:16:00 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /ywkj/tomcat/webapps/host-manager
Nov 25, 2016 9:16:00 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /ywkj/tomcat/webapps/host-manager has finished in 557 ms
Nov 25, 2016 9:16:00 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /ywkj/tomcat/webapps/docs
Nov 25, 2016 9:16:01 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /ywkj/tomcat/webapps/docs has finished in 310 ms
Nov 25, 2016 9:16:01 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /ywkj/tomcat/webapps/examples
Nov 25, 2016 9:16:03 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /ywkj/tomcat/webapps/examples has finished in 2,207 ms
Nov 25, 2016 9:16:03 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /ywkj/tomcat/webapps/ROOT
Nov 25, 2016 9:16:03 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /ywkj/tomcat/webapps/ROOT has finished in 283 ms
Nov 25, 2016 9:16:03 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Nov 25, 2016 9:16:04 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Nov 25, 2016 9:16:04 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 69012 ms
Nov 25, 2016 9:16:04 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Nov 25, 2016 9:16:43 AM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins
Nov 25, 2016 9:16:43 AM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Nov 25, 2016 9:16:43 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Nov 25, 2016 9:16:53 AM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Nov 25, 2016 9:16:53 AM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Nov 25, 2016 9:17:04 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Started Download metadata
Nov 25, 2016 9:17:08 AM org.jenkinsci.main.modules.sshd.SSHD start
INFO: Started SSHD at port 36605
Nov 25, 2016 9:17:08 AM jenkins.InitReactorRunner$1 onAttained
INFO: Completed initialization
Nov 25, 2016 9:17:08 AM hudson.WebAppMain$3 run
INFO: Jenkins is fully up and running
很迅速的搭建好了一个jenkins