有一项重要的参数 -v 目录挂载,就是让容器内部目录和宿主主机目录关联起来,这样就可以直接操作宿主主机目录而不用再操作具体容器了
比如在2中,我们要发布一个war包,是通过
sudo docker cp demo.war tomcat_xiao:/usr/local/tomcat/webapps
来发布的,有没有更快捷的方式呢?
肯定有, 没有 我就不会在这里写这些玩意儿了
sudo docker run -p 8822:8080 --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.0 9f2c1a649a75 2 hours ago 108MB nginx latest 3f8a4339aadd 9 days ago 108MB ubuntu 16.04 00fd29ccc6f1 3 weeks ago 111MB xiaochangwei@ubuntu:~/test$ 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$ sudo docker run -p 8822:8080 --name tomcat_xiao_volume -v /home/xiaochangwei/test:/usr/local/tomcat/webapps 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 08:32:20.580 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.24 05-Jan-2018 08:32:20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Nov 27 2017 13:05:30 UTC 05-Jan-2018 08:32:20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.24.0 05-Jan-2018 08:32:20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux 05-Jan-2018 08:32:20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.10.0-28-generic 05-Jan-2018 08:32:20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64 05-Jan-2018 08:32:20.641 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/jdk/jre 05-Jan-2018 08:32:20.642 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_121-b13 05-Jan-2018 08:32:20.642 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 05-Jan-2018 08:32:20.642 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat 05-Jan-2018 08:32:20.642 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat 05-Jan-2018 08:32:20.642 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 08:32:20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 05-Jan-2018 08:32:20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 05-Jan-2018 08:32:20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources 05-Jan-2018 08:32:20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms128m 05-Jan-2018 08:32:20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx1024m 05-Jan-2018 08:32:20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:PermSize=64M 05-Jan-2018 08:32:20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:MaxPermSize=512M 05-Jan-2018 08:32:20.648 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs= 05-Jan-2018 08:32:20.649 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat 05-Jan-2018 08:32:20.649 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat 05-Jan-2018 08:32:20.649 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp 05-Jan-2018 08:32: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] 05-Jan-2018 08:32:21.293 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"] 05-Jan-2018 08:32:21.358 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 05-Jan-2018 08:32:21.370 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"] 05-Jan-2018 08:32:21.374 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 05-Jan-2018 08:32:21.375 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2178 ms 05-Jan-2018 08:32:21.432 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina] 05-Jan-2018 08:32:21.432 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.24 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] 05-Jan-2018 08:32:24.342 INFO [localhost-startStop-1] 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. 08:32:24.799 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletConfigInitParams' with lowest search precedence 08:32:24.813 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletContextInitParams' with lowest search precedence 08:32:24.832 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'jndiProperties' with lowest search precedence 08:32:24.832 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemProperties' with lowest search precedence 08:32:24.832 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemEnvironment' with lowest search precedence 08:32:24.833 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [StubPropertySource@1897128678 {name='servletConfigInitParams', properties=java.lang.Object@6b18d91f}, StubPropertySource@1347718626 {name='servletContextInitParams', properties=java.lang.Object@4ba81d05}, JndiPropertySource@633520708 {name='jndiProperties', properties=org.springframework.jndi.JndiLocatorDelegate@83f37c2}, MapPropertySource@2087751866 {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@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}}] 08:32:24.844 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams' . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.9.RELEASE) 2018-01-05 08:32:26.068 INFO 13 --- [ost-startStop-1] com.example.demo.ServletInitializer : Starting ServletInitializer v0.0.1-SNAPSHOT on 2dcd945938e8 with PID 13 (/usr/local/tomcat/webapps/demo/WEB-INF/classes started by root in /) 2018-01-05 08:32:26.180 INFO 13 --- [ost-startStop-1] com.example.demo.ServletInitializer : No active profile set, falling back to default profiles: default 2018-01-05 08:32:26.357 INFO 13 --- [ost-startStop-1] ationConfigEmbeddedWebApplicationContext : Refreshing 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:28.732 INFO 13 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2374 ms 2018-01-05 08:32:29.920 INFO 13 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2018-01-05 08:32:29.930 INFO 13 --- [ost-startStop-1] 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] 2018-01-05 08:32:31.667 INFO 13 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-01-05 08:32:31.699 INFO 13 --- [ost-startStop-1] com.example.demo.ServletInitializer : Started ServletInitializer in 6.843 seconds (JVM running for 13.352) 05-Jan-2018 08:32:31.792 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/demo.war] has finished in [10,278] ms 05-Jan-2018 08:32:31.793 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/tomcat] 05-Jan-2018 08:32:31.846 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/tomcat] has finished in [52] ms 05-Jan-2018 08:32:31.846 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/maven] 05-Jan-2018 08:32:31.874 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/maven] has finished in [27] ms 05-Jan-2018 08:32:31.878 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/jdk] 05-Jan-2018 08:32:31.919 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/jdk] has finished in [41] ms 05-Jan-2018 08:32:31.926 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"] 05-Jan-2018 08:32:31.958 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 05-Jan-2018 08:32:31.980 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 10604 ms
按照说明,如果在宿主主机的目录中再放一个war包,容器也应该自动部署,下面验证下
为了方便,我直接复制了demo.war
xiaochangwei@ubuntu:~/test$ ls -l total 14184 drwxr-x--- 5 root root 4096 Jan 5 00:32 demo -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$ xiaochangwei@ubuntu:~/test$ xiaochangwei@ubuntu:~/test$ cp -p demo.war demo2.war xiaochangwei@ubuntu:~/test$ ll total 28360 drwxrwxr-x 7 xiaochangwei xiaochangwei 4096 Jan 5 00:41 ./ drwxr-xr-x 18 xiaochangwei xiaochangwei 4096 Dec 20 23:01 ../ drwxr-x--- 5 root root 4096 Jan 5 00:32 demo/ drwxr-x--- 5 root root 4096 Jan 5 00:41 demo2/ -rw-rw-r-- 1 xiaochangwei xiaochangwei 14501238 Dec 19 23:29 demo2.war -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$
然后看容器的控制台:
05-Jan-2018 08:32:31.926 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"] 05-Jan-2018 08:32:31.958 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 05-Jan-2018 08:32:31.980 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 10604 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] 2018-01-05 08:41:23.862 INFO 13 --- [ost-startStop-2] 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. 08:41:24.163 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletConfigInitParams' with lowest search precedence 08:41:24.165 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'servletContextInitParams' with lowest search precedence 08:41:24.173 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'jndiProperties' with lowest search precedence 08:41:24.178 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemProperties' with lowest search precedence 08:41:24.178 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding PropertySource 'systemEnvironment' with lowest search precedence 08:41:24.178 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [StubPropertySource@165669309 {name='servletConfigInitParams', properties=java.lang.Object@2636bd14}, StubPropertySource@1385884584 {name='servletContextInitParams', properties=java.lang.Object@33ec3b2}, JndiPropertySource@1968853097 {name='jndiProperties', properties=org.springframework.jndi.JndiLocatorDelegate@66178dcb}, MapPropertySource@1666575626 {name='systemProperties', properties={java.vendor=Oracle Corporation, sun.java.launcher=SUN_STANDARD, catalina.base=/usr/local/tomcat, sun.management.compiler=HotSpot 64-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=13, jdk.tls.ephemeralDHKeySize=2048, java.version=1.8.0_121, java.util.logging.manager=org.apache.juli.ClassLoaderLogManager, user.timezone=Etc/UTC, sun.arch.data.model=64, 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.4-1968, 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.0-28-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) 64-Bit Server VM, ignore.endorsed.dirs=, file.encoding=ANSI_X3.4-1968, java.specification.version=1.8}}, SystemEnvironmentPropertySource@377717121 {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}}] 08:41:24.181 [localhost-startStop-2] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams' . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.9.RELEASE) 2018-01-05 08:41:25.139 INFO 13 --- [ost-startStop-2] com.example.demo.ServletInitializer : Starting ServletInitializer v0.0.1-SNAPSHOT on 2dcd945938e8 with PID 13 (/usr/local/tomcat/webapps/demo2/WEB-INF/classes started by root in /) 2018-01-05 08:41:25.140 INFO 13 --- [ost-startStop-2] com.example.demo.ServletInitializer : No active profile set, falling back to default profiles: default 2018-01-05 08:41:25.292 INFO 13 --- [ost-startStop-2] ationConfigEmbeddedWebApplicationContext : Refreshing 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:27.126 INFO 13 --- [ost-startStop-2] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1834 ms 2018-01-05 08:41:28.082 INFO 13 --- [ost-startStop-2] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2018-01-05 08:41:28.083 INFO 13 --- [ost-startStop-2] 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] 2018-01-05 08:41:29.591 INFO 13 --- [ost-startStop-2] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-01-05 08:41:29.616 INFO 13 --- [ost-startStop-2] com.example.demo.ServletInitializer : Started ServletInitializer in 5.421 seconds (JVM running for 551.268) 05-Jan-2018 08:41:29.632 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/demo2.war] has finished in [7,459] ms
证明我们的猜想和实际情况是一致的
这样,我们就可以在宿主主机下根据不同的容器建立对应的便于记忆的目录路径,有发布需求的时候,直接将war包拷贝到宿主主机目录即可,容器叫什么名字,对应的容器的发布路径在哪里就与发布
总结
以上所述是小编给大家介绍的docker容器挂载宿主主机目录的操作方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!