docker:(3)docker容器挂载宿主主机目录

有一项重要的参数 -v 目录挂载,就是让容器内部目录和宿主主机目录关联起来,这样就可以直接操作宿主主机目录而不用再操作具体容器了

比如在2中,我们要发布一个war包,是通过

sudo docker cp demo.war tomcat_xiao:/usr/local/tomcat/webapps

来发布的,有没有更快捷的方式呢?

肯定有, 没有 我就不会在这里写这些玩意儿了

sudo docker run -p : --name tomcat_xiao_volume -v /home/xiaochangwei/test:/usr/local/tomcat/webapps xiaochangwei/tomcat:v1

  -p     不解释

  --name   不解释

  -v /home/xiaochangwei/test:/usr/local/tomcat/webapps 就是将宿主主机目录和容器目录建立映射关系,冒号前为宿主主机目录,冒号后为容器对应目录

执行上面的命令启动,这次启动就和上一篇文章中的启动日志有点差异了:差异就在容器启动时,tomcat加载了我们映射的宿主主机目录中的war包

xiaochangwei@ubuntu:~/test$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
xiaochangwei@ubuntu:~/test$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xiaochangwei/tomcat v1 62cedd29ce8f About an hour ago 505MB
xiaochangwei/nginx v1. 9f2c1a649a75 hours ago 108MB
nginx latest 3f8a4339aadd days ago 108MB
ubuntu 16.04 00fd29ccc6f1 weeks ago 111MB
xiaochangwei@ubuntu:~/test$
xiaochangwei@ubuntu:~/test$ pwd
/home/xiaochangwei/test
xiaochangwei@ubuntu:~/test$ ls -l
total
-rw-rw-r-- xiaochangwei xiaochangwei Dec : demo.war
-rw-rw-r-- xiaochangwei xiaochangwei Jan : Dockerfile
drwxr-xr-x xiaochangwei xiaochangwei Dec jdk
drwxrwxr-x xiaochangwei xiaochangwei Dec : maven
drwxrwxr-x xiaochangwei xiaochangwei Dec : tomcat
xiaochangwei@ubuntu:~/test$ sudo docker run -p : --name tomcat_xiao_volume -v /home/xiaochangwei/test:/usr/local/tomcat/webapps xiaochangwei/tomcat:v1
Tomcat started.
Java HotSpot(TM) -Bit Server VM warning: ignoring option PermSize=64M; support was removed in 8.0
Java HotSpot(TM) -Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
-Jan- ::20.580 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.
-Jan- ::20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Nov :: UTC
-Jan- ::20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.24.0
-Jan- ::20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
-Jan- ::20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.10.--generic
-Jan- ::20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
-Jan- ::20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/jdk/jre
-Jan- ::20.642 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_121-b13
-Jan- ::20.642 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
-Jan- ::20.642 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat
-Jan- ::20.642 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat
-Jan- ::20.642 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
-Jan- ::20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Jan- ::20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=
-Jan- ::20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
-Jan- ::20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms128m
-Jan- ::20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx1024m
-Jan- ::20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:PermSize=64M
-Jan- ::20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:MaxPermSize=512M
-Jan- ::20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
-Jan- ::20.649 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
-Jan- ::20.649 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
-Jan- ::20.649 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
-Jan- ::20.649 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]
-Jan- ::21.293 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
-Jan- ::21.358 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
-Jan- ::21.370 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
-Jan- ::21.374 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
-Jan- ::21.375 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in ms
-Jan- ::21.432 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
-Jan- ::21.432 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.
05-Jan-2018 08:32:21.513 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/demo.war]
-Jan- ::24.342 INFO [localhost-startStop-] 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.
::24.799 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletConfigInitParams' with lowest search precedence
::24.813 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletContextInitParams' with lowest search precedence
::24.832 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'jndiProperties' with lowest search precedence
::24.832 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemProperties' with lowest search precedence
::24.832 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemEnvironment' with lowest search precedence
::24.833 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [StubPropertySource@ {name='servletConfigInitParams', properties=java.lang.Object@6b18d91f}, StubPropertySource@ {name='servletContextInitParams', properties=java.lang.Object@4ba81d05}, JndiPropertySource@ {name='jndiProperties', properties=org.springframework.jndi.JndiLocatorDelegate@83f37c2}, MapPropertySource@ {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.-, 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 -Bit Tiered Compilers, os.version=4.10.--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.-, 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=, 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=, 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@2000415236 {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=2dcd945938e8, 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}}]
::24.844 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams' . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.9.RELEASE) -- ::26.068 INFO --- [ost-startStop-] com.example.demo.ServletInitializer : Starting ServletInitializer v0.0.1-SNAPSHOT on 2dcd945938e8 with PID (/usr/local/tomcat/webapps/demo/WEB-INF/classes started by root in /)
-- ::26.180 INFO --- [ost-startStop-] com.example.demo.ServletInitializer : No active profile set, falling back to default profiles: default
-- ::26.357 INFO --- [ost-startStop-] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@77b0904a: startup date [Fri Jan :: UTC ]; root of context hierarchy
-- ::28.732 INFO --- [ost-startStop-] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in ms
-- ::29.920 INFO --- [ost-startStop-] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
-- ::29.930 INFO --- [ost-startStop-] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*]
2018-01-05 08:32:29.934 INFO 13 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-05 08:32:29.935 INFO 13 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-01-05 08:32:29.935 INFO 13 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-01-05 08:32:29.935 INFO 13 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-01-05 08:32:30.900 INFO 13 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@77b0904a: startup date [Fri Jan 05 08:32:26 UTC 2018]; root of context hierarchy
2018-01-05 08:32:31.079 INFO 13 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/test]}" onto public java.lang.String com.example.demo.web.TEst.test()
2018-01-05 08:32:31.084 INFO 13 --- [ost-startStop-1] 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 08:32:31.091 INFO 13 --- [ost-startStop-1] 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 08:32:31.185 INFO 13 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-05 08:32:31.186 INFO 13 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-05 08:32:31.302 INFO 13 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
-- ::31.667 INFO --- [ost-startStop-] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
-- ::31.699 INFO --- [ost-startStop-] com.example.demo.ServletInitializer : Started ServletInitializer in 6.843 seconds (JVM running for 13.352)
-Jan- ::31.792 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/demo.war] has finished in [,] ms
-Jan- ::31.793 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/tomcat]
-Jan- ::31.846 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/tomcat] has finished in [] ms
-Jan- ::31.846 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/maven]
-Jan- ::31.874 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/maven] has finished in [] ms
-Jan- ::31.878 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/jdk]
-Jan- ::31.919 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/jdk] has finished in [] ms
-Jan- ::31.926 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
-Jan- ::31.958 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
-Jan- ::31.980 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in ms

按照说明,如果在宿主主机的目录中再放一个war包,容器也应该自动部署,下面验证下

为了方便,我直接复制了demo.war

xiaochangwei@ubuntu:~/test$ ls -l
total
drwxr-x--- root root Jan : demo
-rw-rw-r-- xiaochangwei xiaochangwei Dec : demo.war
-rw-rw-r-- xiaochangwei xiaochangwei Jan : Dockerfile
drwxr-xr-x xiaochangwei xiaochangwei Dec jdk
drwxrwxr-x xiaochangwei xiaochangwei Dec : maven
drwxrwxr-x xiaochangwei xiaochangwei Dec : tomcat
xiaochangwei@ubuntu:~/test$
xiaochangwei@ubuntu:~/test$
xiaochangwei@ubuntu:~/test$ cp -p demo.war demo2.war
xiaochangwei@ubuntu:~/test$ ll
total
drwxrwxr-x xiaochangwei xiaochangwei Jan : ./
drwxr-xr-x xiaochangwei xiaochangwei Dec : ../
drwxr-x--- root root Jan : demo/
drwxr-x--- root root Jan : demo2/
-rw-rw-r-- 1 xiaochangwei xiaochangwei 14501238 Dec 19 23:29 demo2.war
-rw-rw-r-- xiaochangwei xiaochangwei Dec : demo.war
-rw-rw-r-- xiaochangwei xiaochangwei Jan : Dockerfile
drwxr-xr-x xiaochangwei xiaochangwei Dec jdk/
drwxrwxr-x xiaochangwei xiaochangwei Dec : maven/
drwxrwxr-x xiaochangwei xiaochangwei Dec : tomcat/
xiaochangwei@ubuntu:~/test$

然后看容器的控制台:

-Jan- ::31.926 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
-Jan- ::31.958 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
-Jan- ::31.980 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in ms 05-Jan-2018 08:41:22.174 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/demo2.war]
-- ::23.862 INFO --- [ost-startStop-] org.apache.jasper.servlet.TldScanner : 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.
::24.163 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletConfigInitParams' with lowest search precedence
::24.165 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletContextInitParams' with lowest search precedence
::24.173 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'jndiProperties' with lowest search precedence
::24.178 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemProperties' with lowest search precedence
::24.178 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemEnvironment' with lowest search precedence
::24.178 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [StubPropertySource@ {name='servletConfigInitParams', properties=java.lang.Object@2636bd14}, StubPropertySource@ {name='servletContextInitParams', properties=java.lang.Object@33ec3b2}, JndiPropertySource@ {name='jndiProperties', properties=org.springframework.jndi.JndiLocatorDelegate@66178dcb}, MapPropertySource@ {name='systemProperties', properties={java.vendor=Oracle Corporation, sun.java.launcher=SUN_STANDARD, catalina.base=/usr/local/tomcat, sun.management.compiler=HotSpot -Bit Tiered Compilers, catalina.useNaming=true, os.name=Linux, 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, java.util.logging.config.file=/usr/local/tomcat/conf/logging.properties, java.vm.specification.vendor=Oracle Corporation, java.runtime.version=1.8.0_121-b13, user.name=root, tomcat.util.scan.StandardJarScanFilter.jarsToScan=log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar, shared.loader=, tomcat.util.buf.StringCache.byte.enabled=true, user.language=en, java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory, sun.boot.library.path=/usr/local/jdk/jre/lib/amd64, PID=, jdk.tls.ephemeralDHKeySize=, java.version=1.8.0_121, java.util.logging.manager=org.apache.juli.ClassLoaderLogManager, user.timezone=Etc/UTC, sun.arch.data.model=, java.util.concurrent.ForkJoinPool.common.threadFactory=org.apache.catalina.startup.SafeForkJoinWorkerThreadFactory, java.endorsed.dirs=/usr/local/jdk/jre/lib/endorsed, sun.cpu.isalist=, sun.jnu.encoding=ANSI_X3.-, file.encoding.pkg=sun.io, package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat., file.separator=/, java.specification.name=Java Platform API Specification, java.class.version=52.0, user.country=US, java.home=/usr/local/jdk/jre, java.vm.info=mixed mode, os.version=4.10.--generic, path.separator=:, java.vm.version=25.121-b13, org.jboss.logging.provider=slf4j, java.protocol.handler.pkgs=org.apache.catalina.webresources, java.awt.printerjob=sun.print.PSPrinterJob, sun.io.unicode.encoding=UnicodeLittle, awt.toolkit=sun.awt.X11.XToolkit, package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat., java.naming.factory.url.pkgs=org.apache.naming, user.home=/root, java.specification.vendor=Oracle Corporation, 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, java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib, java.vendor.url=http://java.oracle.com/, spring.beaninfo.ignore=true, java.vm.vendor=Oracle Corporation, common.loader="${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar", java.runtime.name=Java(TM) SE Runtime Environment, sun.java.command=org.apache.catalina.startup.Bootstrap start, java.class.path=/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.8, catalina.home=/usr/local/tomcat, sun.cpu.endian=little, sun.os.patch.level=unknown, java.awt.headless=true, java.io.tmpdir=/usr/local/tomcat/temp, java.vendor.url.bug=http://bugreport.sun.com/bugreport/, server.loader=, os.arch=amd64, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.ext.dirs=/usr/local/jdk/jre/lib/ext:/usr/java/packages/lib/ext, user.dir=/, line.separator=
, java.vm.name=Java HotSpot(TM) -Bit Server VM, ignore.endorsed.dirs=, file.encoding=ANSI_X3.-, java.specification.version=1.8}}, SystemEnvironmentPropertySource@ {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=2dcd945938e8, 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}}]
::24.181 [localhost-startStop-] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams' . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.9.RELEASE) -- ::25.139 INFO --- [ost-startStop-] com.example.demo.ServletInitializer : Starting ServletInitializer v0.0.1-SNAPSHOT on 2dcd945938e8 with PID (/usr/local/tomcat/webapps/demo2/WEB-INF/classes started by root in /)
-- ::25.140 INFO --- [ost-startStop-] com.example.demo.ServletInitializer : No active profile set, falling back to default profiles: default
-- ::25.292 INFO --- [ost-startStop-] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7d220249: startup date [Fri Jan :: UTC ]; root of context hierarchy
-- ::27.126 INFO --- [ost-startStop-] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in ms
-- ::28.082 INFO --- [ost-startStop-] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
-- ::28.083 INFO --- [ost-startStop-] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*]
2018-01-05 08:41:28.084 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-05 08:41:28.084 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-01-05 08:41:28.084 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-01-05 08:41:28.084 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-01-05 08:41:28.924 INFO 13 --- [ost-startStop-2] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7d220249: startup date [Fri Jan 05 08:41:25 UTC 2018]; root of context hierarchy
2018-01-05 08:41:29.087 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 08:41:29.099 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 08:41:29.100 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 08:41:29.181 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 08:41:29.181 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 08:41:29.296 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]
-- ::29.591 INFO --- [ost-startStop-] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
-- ::29.616 INFO --- [ost-startStop-] com.example.demo.ServletInitializer : Started ServletInitializer in 5.421 seconds (JVM running for 551.268)
-Jan- ::29.632 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/demo2.war] has finished in [,] ms

证明我们的猜想和实际情况是一致的

这样,我们就可以在宿主主机下根据不同的容器建立对应的便于记忆的目录路径,有发布需求的时候,直接将war包拷贝到宿主主机目录即可,容器叫什么名字,对应的容器的发布路径在哪里就与发布者无关了

下一篇文章我将讲解和jekins集成,让代码编译好后自动部署到docker中

2015年11月写了一篇文章,是代码在jenkins中编译好后发布到远端tomcat的,可以参考下 http://www.cnblogs.com/xiaochangwei/p/4952644.html

我的发言结束了 谢谢大家 docker:(3)docker容器挂载宿主主机目录

上一篇:关于SQL中的Update语句


下一篇:【vue】vue全家桶