docker:(2)通过Dockerfile构建镜像并发布web项目
上一篇讲解了docker的基本使用 http://www.cnblogs.com/xiaochangwei/p/8204511.html
虽然通过修改获取到的镜像可以达到使用目的,但是多操作几次就会发现,操作还是比较繁琐,扩充也不是很方便
而取而代之的方法就是通过Dockerfile来构建自己想要的镜像,
在linux下编译过C程序的同学肯定知道Makefile, Dockerfile和其一样,就是为了达到快速编译(生成)想要的镜像的
下面以j2ee最常用的场景:在ubuntu下配置jdk环境,并用tomcat发布一个war包的web项目
1.准备好需要的jdk 和 tomcat
xiaochangwei@ubuntu:~/test$ date Thu Jan 4 23:00:38 PST 2018 xiaochangwei@ubuntu:~/test$ ls -l total 14180 -rw-rw-r-- 1 xiaochangwei xiaochangwei 14501238 Dec 19 23:29 demo.war -rw-rw-r-- 1 xiaochangwei xiaochangwei 551 Jan 4 18:18 Dockerfile drwxr-xr-x 8 xiaochangwei xiaochangwei 4096 Dec 12 2016 jdk drwxrwxr-x 6 xiaochangwei xiaochangwei 4096 Dec 20 21:51 maven drwxrwxr-x 9 xiaochangwei xiaochangwei 4096 Dec 20 18:28 tomcat xiaochangwei@ubuntu:~/test$
这里我将jdk和tomcat的tar.gz 包都通过 tar -zxvf解压了 并通过mv 修改了文件夹名字为jdk和tomcat
(其实不解压也可以,2中说明为啥我要解压,为啥不用解压而我又先解压了)
2.编写Dockerfile(示例如下)
1 FROM ubuntu:16.04 2 MAINTAINER changw.xiao@qq.com 3 COPY ./jdk /usr/local/jdk 4 COPY ./tomcat /tomcat 5 COPY ./maven /usr/local/maven 6 7 ENV M2_HOME=/usr/local/maven 8 ENV JAVA_HOME /usr/local/jdk 9 ENV JRE_HOME $JAVA_HOME/jre 10 ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib 11 ENV PATH $PATH:$JAVA_HOME/bin 12 ENV PATH $PATH:$M2_HOME/bin 13 ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M 14 RUN cd /tomcat/logs && echo "1" >>count.txt 15 ENTRYPOINT /tomcat/bin/startup.sh && tail -F /tomcat/logs/catalina.out
根据显示的行号来解释
1.我们制作镜像的基础,在ubuntu16.04的系统上构建后续操作
2.维护者信息
3~5.复制当前目录下的jdk目录 到容器内部的/usr/local/jdk目录下
解释下:
Dockerfile提供了COPY 和 ADD 两种方式
COPY : COPY ./jdk /usr/local/jdk #直接原样拷贝过去
ADD : ADD ./jdk-8u121-linux-x64.tar.gz /usr/local/java #拷贝过去,如果是压缩包还会自动帮着解压,本来是好事,但是解压后文件夹名字一长串,不便于记忆,就直接先解压好重命名好了再COPY过去
7~13.一看就知道了 通过 ENV 来设置各种环境变量
14.为了示例RUN的使用, 通过RUN命令,后面就可以执行各种linux命令
15.表示启动容器后执行的操作
将上述文件保存为Dockerfile 注意大小写,没有后缀,然后进入到该目录,执行命令构建镜像
sudo docker build -t xiaochangwei/tomcat:v1 --rm=true .
#如果改变了Dockerfile名字,则需要指定 -f 文件名称
xiaochangwei/tomcat:v1 镜像的名字及tag, 最后的点代表当前目录
xiaochangwei@ubuntu:~/test$ pwd /home/xiaochangwei/test xiaochangwei@ubuntu:~/test$ ls -l total 14180 -rw-rw-r-- 1 xiaochangwei xiaochangwei 14501238 Dec 19 23:29 demo.war -rw-rw-r-- 1 xiaochangwei xiaochangwei 551 Jan 4 18:18 Dockerfile drwxr-xr-x 8 xiaochangwei xiaochangwei 4096 Dec 12 2016 jdk drwxrwxr-x 6 xiaochangwei xiaochangwei 4096 Dec 20 21:51 maven drwxrwxr-x 9 xiaochangwei xiaochangwei 4096 Dec 20 18:28 tomcat xiaochangwei@ubuntu:~/test$ cat Dockerfile FROM ubuntu:16.04 MAINTAINER changw.xiao@qq.com COPY ./jdk /usr/local/jdk COPY ./tomcat /usr/local/tomcat COPY ./maven /usr/local/maven ENV M2_HOME=/usr/local/maven ENV JAVA_HOME /usr/local/jdk ENV JRE_HOME $JAVA_HOME/jre ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib ENV PATH $PATH:$JAVA_HOME/bin ENV PATH $PATH:$M2_HOME/bin ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M #RUN cd /usr/local/tomcat/logs && echo "1" >>count.txt ENTRYPOINT /usr/local/tomcat/bin/startup.sh && tail -F /usr/local/tomcat/logs/catalina.out xiaochangwei@ubuntu:~/test$ xiaochangwei@ubuntu:~/test$ sudo docker build -t xiaochangwei/tomcat:v1 --rm=true . Sending build context to Docker daemon 410.8MB Step 1/13 : FROM ubuntu:16.04 ---> 00fd29ccc6f1 Step 2/13 : MAINTAINER changw.xiao@qq.com ---> Running in 76c030597a76 ---> b60e5688bbeb Removing intermediate container 76c030597a76 Step 3/13 : COPY ./jdk /usr/local/jdk ---> 7ed40312898c Removing intermediate container 4bafdad847ea Step 4/13 : COPY ./tomcat /usr/local/tomcat ---> b3f27950da80 Removing intermediate container 3b47f6478612 Step 5/13 : COPY ./maven /usr/local/maven ---> 693be0d164e1 Removing intermediate container 384a0c731ee5 Step 6/13 : ENV M2_HOME /usr/local/maven ---> Running in 976e32621210 ---> 26c40484df7c Removing intermediate container 976e32621210 Step 7/13 : ENV JAVA_HOME /usr/local/jdk ---> Running in d0ae07b77311 ---> 198ceaed2dcf Removing intermediate container d0ae07b77311 Step 8/13 : ENV JRE_HOME $JAVA_HOME/jre ---> Running in ec049c30011d ---> 1c334836ace7 Removing intermediate container ec049c30011d Step 9/13 : ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib ---> Running in 4be76497d654 ---> 70ae97a52bc1 Removing intermediate container 4be76497d654 Step 10/13 : ENV PATH $PATH:$JAVA_HOME/bin ---> Running in 2928a173dced ---> aa1a8b8cc887 Removing intermediate container 2928a173dced Step 11/13 : ENV PATH $PATH:$M2_HOME/bin ---> Running in b79043df89ae ---> 85ad599def5d Removing intermediate container b79043df89ae Step 12/13 : ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M ---> Running in fced93182cb3 ---> e27958a0c46d Removing intermediate container fced93182cb3 Step 13/13 : ENTRYPOINT /usr/local/tomcat/bin/startup.sh && tail -F /usr/local/tomcat/logs/catalina.out ---> Running in ba924a892390 ---> 62cedd29ce8f Removing intermediate container ba924a892390 Successfully built 62cedd29ce8f Successfully tagged xiaochangwei/tomcat:v1 xiaochangwei@ubuntu:~/test$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE xiaochangwei/tomcat v1 62cedd29ce8f 48 seconds ago 505MB xiaochangwei/nginx v1.0 9f2c1a649a75 About an hour ago 108MB nginx latest 3f8a4339aadd 9 days ago 108MB ubuntu 16.04 00fd29ccc6f1 3 weeks ago 111MB xiaochangwei@ubuntu:~/test$
至此,我们需要的tomcat镜像就已经制作完成了
也发布到docker cloud上去吧
上传时间根据网络和镜像大小来决定,网络差的同学多等待下
xiaochangwei@ubuntu:~/test$ xiaochangwei@ubuntu:~/test$ sudo docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username (xiaochangwei): Password: Login Succeeded xiaochangwei@ubuntu:~/test$ sudo docker push xiaochangwei/tomcat:v1 The push refers to a repository [docker.io/xiaochangwei/tomcat] c43202b7d442: Pushed 7c53d0ebf3ba: Pushed ff2a15c80240: Pushed f17fc24fb8d0: Pushed 6458f770d435: Pushed 5a876f8f1a3d: Pushed d2f8c05d353b: Pushed 48e0baf45d4d: Pushed v1: digest: sha256:4c4ca8f7dc3ef3c0cfeea91c9dfe44bc1611288a1ff30a919b312f2cfd5cd67d size: 1992 xiaochangwei@ubuntu:~/test$
docker cloud上也有了,不过提醒下,这里要稍微多等下,有时候命令行显示上传完了,但是网页端还是没有,不用急,多等会儿
启动试试看
sudo docker run -p 8899:8080 --name tomcat_xiao xiaochangwei/tomcat:v1
如果想后台运行 可以在run后加 -d 参数即:sudo docker run -d -p 8899:8080 --name tomcat_xiao xiaochangwei/tomcat:v1 其余参数不解释,看上一篇文章
xiaochangwei@ubuntu:~/test$ sudo docker run -p 8899:8080 --name tomcat_xiao xiaochangwei/tomcat:v1 Tomcat started. Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=64M; support was removed in 8.0 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0 05-Jan-2018 07:22:50.192 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.24 05-Jan-2018 07:22:50.272 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Nov 27 2017 13:05:30 UTC 05-Jan-2018 07:22:50.275 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.24.0 05-Jan-2018 07:22:50.276 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux 05-Jan-2018 07:22:50.277 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.10.0-28-generic 05-Jan-2018 07:22:50.277 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64 05-Jan-2018 07:22:50.277 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/jdk/jre 05-Jan-2018 07:22:50.277 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_121-b13 05-Jan-2018 07:22:50.277 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 05-Jan-2018 07:22:50.277 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat 05-Jan-2018 07:22:50.277 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat 05-Jan-2018 07:22:50.278 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties 05-Jan-2018 07:22:50.284 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 05-Jan-2018 07:22:50.284 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 05-Jan-2018 07:22:50.284 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources 05-Jan-2018 07:22:50.284 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms128m 05-Jan-2018 07:22:50.285 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx1024m 05-Jan-2018 07:22:50.285 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:PermSize=64M 05-Jan-2018 07:22:50.285 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:MaxPermSize=512M 05-Jan-2018 07:22:50.285 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs= 05-Jan-2018 07:22:50.285 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat 05-Jan-2018 07:22:50.285 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat 05-Jan-2018 07:22:50.285 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp 05-Jan-2018 07:22:50.285 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent 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] 05-Jan-2018 07:22:51.504 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"] 05-Jan-2018 07:22:51.661 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 05-Jan-2018 07:22:51.692 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"] 05-Jan-2018 07:22:51.695 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 05-Jan-2018 07:22:51.696 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2713 ms 05-Jan-2018 07:22:51.769 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina] 05-Jan-2018 07:22:51.770 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.24 05-Jan-2018 07:22:51.809 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/manager] 05-Jan-2018 07:22:52.731 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/manager] has finished in [921] ms 05-Jan-2018 07:22:52.732 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/docs] 05-Jan-2018 07:22:52.782 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/docs] has finished in [51] ms 05-Jan-2018 07:22:52.783 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/ROOT] 05-Jan-2018 07:22:52.819 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/ROOT] has finished in [36] ms 05-Jan-2018 07:22:52.820 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/host-manager] 05-Jan-2018 07:22:52.881 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/host-manager] has finished in [61] ms 05-Jan-2018 07:22:52.886 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/examples]
看见猫了就表示对了
然后问题又来了,容器倒是启动起来了,但是怎么把我们自己的war包丢里面运行起来呢?
sudo docker cp demo.war tomcat_xiao:/usr/local/tomcat/webapps
demo.war 不解释
tomcat_xiao:/usr/local/tomcat/webapps 冒号前面为容器名称或者id, 冒号后面为tomcat的webapps全路径
丢进去就好了,会自动发布的,不需要我们再自己去启动tomcat了,因为容器启动后tomcat就默认启动了 Dockerfile最后一行就是启动tomcat
丢进去后,控制台就会检测到,并自动部署
05-Jan-2018 07:22:53.527 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 05-Jan-2018 07:22:53.553 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1857 ms 05-Jan-2018 07:28:43.625 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/demo.war] 05-Jan-2018 07:28:45.511 INFO [localhost-startStop-2] org.apache.jasper.servlet.TldScanner.scanJars 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. 07:28:45.983 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletConfigInitParams' with lowest search precedence 07:28:45.991 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletContextInitParams' with lowest search precedence 07:28:45.999 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'jndiProperties' with lowest search precedence 07:28:46.002 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemProperties' with lowest search precedence 07:28:46.002 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemEnvironment' with lowest search precedence 07:28:46.009 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [StubPropertySource@1987577958 {name='servletConfigInitParams', properties=java.lang.Object@2ab71e10}, StubPropertySource@522595491 {name='servletContextInitParams', properties=java.lang.Object@11437082}, JndiPropertySource@667841012 {name='jndiProperties', properties=org.springframework.jndi.JndiLocatorDelegate@359bbc83}, MapPropertySource@469163431 {name='systemProperties', properties={java.runtime.name=Java(TM) SE Runtime Environment, java.protocol.handler.pkgs=org.apache.catalina.webresources, sun.boot.library.path=/usr/local/jdk/jre/lib/amd64, java.vm.version=25.121-b13, shared.loader=, java.vm.vendor=Oracle Corporation, java.vendor.url=http://java.oracle.com/, path.separator=:, tomcat.util.buf.StringCache.byte.enabled=true, java.util.logging.config.file=/usr/local/tomcat/conf/logging.properties, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg=sun.io, user.country=US, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=unknown, tomcat.util.scan.StandardJarScanFilter.jarsToScan=log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/, java.runtime.version=1.8.0_121-b13, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.endorsed.dirs=/usr/local/jdk/jre/lib/endorsed, os.arch=amd64, java.io.tmpdir=/usr/local/tomcat/temp, line.separator= , java.vm.specification.vendor=Oracle Corporation, java.naming.factory.url.pkgs=org.apache.naming, java.util.logging.manager=org.apache.juli.ClassLoaderLogManager, os.name=Linux, ignore.endorsed.dirs=, sun.jnu.encoding=ANSI_X3.4-1968, java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib, java.specification.name=Java Platform API Specification, java.class.version=52.0, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, os.version=4.10.0-28-generic, java.util.concurrent.ForkJoinPool.common.threadFactory=org.apache.catalina.startup.SafeForkJoinWorkerThreadFactory, user.home=/root, catalina.useNaming=true, user.timezone=Etc/UTC, java.awt.printerjob=sun.print.PSPrinterJob, file.encoding=ANSI_X3.4-1968, java.specification.version=1.8, tomcat.util.scan.StandardJarScanFilter.jarsToSkip=bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,jaspic-api.jar,catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-storeconfig.jar,catalina-tribes.jar,jasper.jar,jasper-el.jar,ecj-*.jar,tomcat-api.jar,tomcat-util.jar,tomcat-util-scan.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-jni.jar,tomcat-websocket.jar,tomcat-i18n-en.jar,tomcat-i18n-es.jar,tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,tomcat-juli-adapters.jar,catalina-jmx-remote.jar,catalina-ws.jar,tomcat-jdbc.jar,tools.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,jstl.jar,taglibs-standard-spec-*.jar,geronimo-spec-jaxrpc*.jar,wsdl4j*.jar,ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,jmx-tools.jar,jta*.jar,log4j*.jar,mail*.jar,slf4j*.jar,xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,junit.jar,junit-*.jar,hamcrest-*.jar,easymock-*.jar,cglib-*.jar,objenesis-*.jar,ant-launcher.jar,cobertura-*.jar,asm-*.jar,dom4j-*.jar,icu4j-*.jar,jaxen-*.jar,jdom-*.jar,jetty-*.jar,oro-*.jar,servlet-api-*.jar,tagsoup-*.jar,xmlParserAPIs-*.jar,xom-*.jar, catalina.home=/usr/local/tomcat, java.class.path=/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar, user.name=root, java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory, package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat., java.vm.specification.version=1.8, sun.java.command=org.apache.catalina.startup.Bootstrap start, java.home=/usr/local/jdk/jre, sun.arch.data.model=64, user.language=en, java.specification.vendor=Oracle Corporation, awt.toolkit=sun.awt.X11.XToolkit, java.vm.info=mixed mode, java.version=1.8.0_121, java.ext.dirs=/usr/local/jdk/jre/lib/ext:/usr/java/packages/lib/ext, sun.boot.class.path=/usr/local/jdk/jre/lib/resources.jar:/usr/local/jdk/jre/lib/rt.jar:/usr/local/jdk/jre/lib/sunrsasign.jar:/usr/local/jdk/jre/lib/jsse.jar:/usr/local/jdk/jre/lib/jce.jar:/usr/local/jdk/jre/lib/charsets.jar:/usr/local/jdk/jre/lib/jfr.jar:/usr/local/jdk/jre/classes, server.loader=, java.vendor=Oracle Corporation, catalina.base=/usr/local/tomcat, jdk.tls.ephemeralDHKeySize=2048, file.separator=/, java.vendor.url.bug=http://bugreport.sun.com/bugreport/, common.loader="${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar", sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat., sun.cpu.isalist=}}, SystemEnvironmentPropertySource@289106235 {name='systemEnvironment', properties={PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/jdk/bin:/usr/local/maven/bin, JRE_HOME=/usr/local/jdk/jre, HOSTNAME=49e64e276429, NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat, M2_HOME=/usr/local/maven, JAVA_HOME=/usr/local/jdk, CATALINA_OPTS=-Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M, JDK_JAVA_OPTIONS= --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED, XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt, PWD=/, CLASSPATH=/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar, HOME=/root}}] 07:28:46.012 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams' . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.9.RELEASE) 2018-01-05 07:28:47.243 INFO 13 --- [ost-startStop-2] com.example.demo.ServletInitializer : Starting ServletInitializer v0.0.1-SNAPSHOT on 49e64e276429 with PID 13 (/usr/local/tomcat/webapps/demo/WEB-INF/classes started by root in /) 2018-01-05 07:28:47.251 INFO 13 --- [ost-startStop-2] com.example.demo.ServletInitializer : No active profile set, falling back to default profiles: default 2018-01-05 07:28:47.466 INFO 13 --- [ost-startStop-2] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@42b2aed8: startup date [Fri Jan 05 07:28:47 UTC 2018]; root of context hierarchy 2018-01-05 07:28:50.020 INFO 13 --- [ost-startStop-2] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2554 ms 2018-01-05 07:28:51.310 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2018-01-05 07:28:51.312 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*] 2018-01-05 07:28:51.312 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2018-01-05 07:28:51.312 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2018-01-05 07:28:51.312 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2018-01-05 07:28:51.318 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-01-05 07:28:52.383 INFO 13 --- [ost-startStop-2] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@42b2aed8: startup date [Fri Jan 05 07:28:47 UTC 2018]; root of context hierarchy 2018-01-05 07:28:52.614 INFO 13 --- [ost-startStop-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/test]}" onto public java.lang.String com.example.demo.web.TEst.test() 2018-01-05 07:28:52.623 INFO 13 --- [ost-startStop-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2018-01-05 07:28:52.625 INFO 13 --- [ost-startStop-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2018-01-05 07:28:52.729 INFO 13 --- [ost-startStop-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-01-05 07:28:52.731 INFO 13 --- [ost-startStop-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-01-05 07:28:52.841 INFO 13 --- [ost-startStop-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-01-05 07:28:53.260 INFO 13 --- [ost-startStop-2] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-01-05 07:28:53.301 INFO 13 --- [ost-startStop-2] com.example.demo.ServletInitializer : Started ServletInitializer in 7.263 seconds (JVM running for 365.437) 05-Jan-2018 07:28:53.326 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/demo.war] has finished in [9,701] ms
好了,满足基本需要了
这里面有一项重要的参数 -v 目录挂载,就是让容器内部目录和宿主主机目录关联起来,这样就可以直接操作宿主主机目录而不用再操作具体容器了 后续文章中进行讲解
后续会讲到
目录挂载
与jenkins整合,实现持续集成
还有暂时没想到的东西