给自己

Last login: Sat Feb  9 02:33:10 2019 from 192.168.17.1
[root@zft ~]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                    NAMES
ae2aff6daf2d        ipple1986/hexo        "hexo server"            35 hours ago        Up 35 hours         0.0.0.0:4000->4000/tcp   some-hexo
cb5b22e06aa5        mysql:5.7.22          "docker-entrypoint.s…"   3 days ago          Up 3 days           0.0.0.0:3306->3306/tcp   mysql
29ff54b3124a        wordpress             "docker-entrypoint.s…"   3 days ago          Up 3 days           0.0.0.0:80->80/tcp       wordpress
c27ece8ced80        portainer/portainer   "/portainer"             7 days ago          Up 7 days           0.0.0.0:9000->9000/tcp   brave_snyder
[root@zft ~]# cd /usr/local/
[root@zft local]# ll
总用量 0
drwxr-xr-x. 2 root root  6 4月  11 2018 bin
drwxr-xr-x. 2 root root  6 4月  11 2018 etc
drwxr-xr-x. 2 root root  6 4月  11 2018 games
drwxr-xr-x. 2 root root  6 4月  11 2018 include
drwxr-xr-x. 2 root root  6 4月  11 2018 lib
drwxr-xr-x. 2 root root  6 4月  11 2018 lib64
drwxr-xr-x. 2 root root  6 4月  11 2018 libexec
drwxr-xr-x. 2 root root  6 4月  11 2018 sbin
drwxr-xr-x. 5 root root 49 2月   5 10:30 share
drwxr-xr-x. 2 root root  6 4月  11 2018 src
[root@zft local]# mkdir docker
[root@zft local]# cd docker/
[root@zft docker]# mkdir tomcat
[root@zft docker]# cd tomcat/
[root@zft tomcat]# vi Dockerfile
FROM tomcat
RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html
~
~

"Dockerfile" [New] 2L, 80C written
[root@zft tomcat]# cat Dockerfile 
FROM tomcat
RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html
[root@zft tomcat]# docker build -t mytomcat .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM tomcat
latest: Pulling from library/tomcat
741437d97401: Pull complete 
34d8874714d7: Pull complete 
0a108aa26679: Pull complete 
eea0f08c7492: Pull complete 
ca74b3d90c15: Pull complete 
f11a643c4a85: Pull complete 
05eafed73b65: Pull complete 
f24105f282aa: Pull complete 
e27e73cbbd3f: Pull complete 
801f808615c2: Pull complete 
294f3735a5f6: Pull complete 
Digest: sha256:2af4741120ac4b2e1993412e34b73565d1b859d8a44b1b5f0e1963d97cc921a1
Status: Downloaded newer image for tomcat:latest
 ---> 168588387c68
Step 2/2 : RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html
 ---> Running in 9df888b059e8
Removing intermediate container 9df888b059e8
 ---> 8b604d034978
Successfully built 8b604d034978
Successfully tagged mytomcat:latest
[root@zft tomcat]# docker images

REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
mytomcat              latest              8b604d034978        16 seconds ago      463MB
tomcat                latest              168588387c68        3 days ago          463MB
mysql                 5.7.25              e47e309f72c8        6 days ago          372MB
portainer/portainer   latest              89c72b64ab63        12 days ago         74.2MB
wordpress             latest              6e880d17852f        2 weeks ago         420MB
mysql                 5.7.22              6bb891430fb6        6 months ago        372MB
ipple1986/hexo        latest              8eb73a3f4772        20 months ago       427MB
[root@zft tomcat]# 
[root@zft tomcat]# docker run -it mytomcat bash
root@1878c9f4985b:/usr/local/tomcat# ls -a
.             CONTRIBUTING.md  README.md      bin      lib             temp
..            LICENSE          RELEASE-NOTES  conf     logs            webapps
BUILDING.txt  NOTICE           RUNNING.txt    include  native-jni-lib  work
root@1878c9f4985b:/usr/local/tomcat# ls -al
total 124
drwxr-sr-x. 1 root staff    21 Feb  9 02:08 .
drwxrwsr-x. 1 root staff    20 Feb  6 16:55 ..
-rw-r--r--. 1 root root  19539 Feb  5 11:45 BUILDING.txt
-rw-r--r--. 1 root root   6090 Feb  5 11:45 CONTRIBUTING.md
-rw-r--r--. 1 root root  57092 Feb  5 11:45 LICENSE
-rw-r--r--. 1 root root   1726 Feb  5 11:45 NOTICE
-rw-r--r--. 1 root root   3255 Feb  5 11:45 README.md
-rw-r--r--. 1 root root   7142 Feb  5 11:45 RELEASE-NOTES
-rw-r--r--. 1 root root  16262 Feb  5 11:45 RUNNING.txt
drwxr-xr-x. 2 root root   4096 Feb  9 02:08 bin
drwxr-sr-x. 2 root root    238 Feb  5 11:45 conf
drwxr-sr-x. 2 root staff    78 Feb  9 02:08 include
drwxr-xr-x. 2 root root   4096 Feb  9 02:08 lib
drwxrwxrwx. 2 root root      6 Feb  5 11:42 logs
drwxr-sr-x. 3 root staff   151 Feb  9 02:08 native-jni-lib
drwxr-xr-x. 2 root root     30 Feb  9 02:08 temp
drwxr-xr-x. 1 root root     18 Feb  5 11:44 webapps
drwxrwxrwx. 2 root root      6 Feb  5 11:42 work
root@1878c9f4985b:/usr/local/tomcat# cd webapps/
root@1878c9f4985b:/usr/local/tomcat/webapps# ll
bash: ll: command not found
root@1878c9f4985b:/usr/local/tomcat/webapps# ls -al
total 4
drwxr-xr-x.  1 root root    18 Feb  5 11:44 .
drwxr-sr-x.  1 root staff   21 Feb  9 02:08 ..
drwxr-xr-x.  1 root root    24 Feb 12 09:46 ROOT
drwxr-xr-x. 14 root root  4096 Feb  9 02:08 docs
drwxr-xr-x.  6 root root    83 Feb  9 02:08 examples
drwxr-xr-x.  5 root root    87 Feb  9 02:08 host-manager
drwxr-xr-x.  5 root root   103 Feb  9 02:08 manager
root@1878c9f4985b:/usr/local/tomcat/webapps# cd ROOT/
root@1878c9f4985b:/usr/local/tomcat/webapps/ROOT# ls -a
.                  bg-button.png    favicon.ico       tomcat.gif
..                 bg-middle.png    index.html        tomcat.png
RELEASE-NOTES.txt  bg-nav-item.png  index.jsp         tomcat.svg
WEB-INF            bg-nav.png       tomcat-power.gif
asf-logo-wide.svg  bg-upper.png     tomcat.css
root@1878c9f4985b:/usr/local/tomcat/webapps/ROOT# cat index.html 
Hello Docker
root@1878c9f4985b:/usr/local/tomcat/webapps/ROOT# exit
exit
[root@zft tomcat]# vi Dockerfile 
FROM tomcat
WORKDIR /usr/local/tomcat/webapps/ROOT/
RUN rm -rf *
RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html
~
~
"Dockerfile" 4L, 133C written
[root@zft tomcat]# docker build -t mytomcat .
Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM tomcat
 ---> 168588387c68
Step 2/4 : WORKDIR /usr/local/tomcat/webapps/ROOT/
 ---> Running in b7c55dd156ab
Removing intermediate container b7c55dd156ab
 ---> 48fd897834d6
Step 3/4 : RUN rm -rf *
 ---> Running in 77dcbdb18573
Removing intermediate container 77dcbdb18573
 ---> 26f9f86285b5
Step 4/4 : RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html
 ---> Running in c7cb4aeb3c52
Removing intermediate container c7cb4aeb3c52
 ---> 3c0cca79ebb6
Successfully built 3c0cca79ebb6
Successfully tagged mytomcat:latest
[root@zft tomcat]# docker run -it --rm mytomcat bash
root@7f46a2e91832:/usr/local/tomcat/webapps/ROOT# ls -al
total 4
drwxr-xr-x. 1 root root 24 Feb 12 09:53 .
drwxr-xr-x. 1 root root 18 Feb  5 11:44 ..
-rw-r--r--. 1 root root 13 Feb 12 09:53 index.html
root@7f46a2e91832:/usr/local/tomcat/webapps/ROOT# exit
exit
[root@zft tomcat]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED              SIZE
mytomcat              latest              3c0cca79ebb6        About a minute ago   463MB
<none>                <none>              8b604d034978        8 minutes ago        463MB
tomcat                latest              168588387c68        3 days ago           463MB
mysql                 5.7.25              e47e309f72c8        6 days ago           372MB
portainer/portainer   latest              89c72b64ab63        12 days ago          74.2MB
wordpress             latest              6e880d17852f        2 weeks ago          420MB
mysql                 5.7.22              6bb891430fb6        6 months ago         372MB
ipple1986/hexo        latest              8eb73a3f4772        20 months ago        427MB
[root@zft tomcat]# docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
[root@zft tomcat]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
mytomcat              latest              3c0cca79ebb6        2 minutes ago       463MB
<none>                <none>              8b604d034978        9 minutes ago       463MB
tomcat                latest              168588387c68        3 days ago          463MB
mysql                 5.7.25              e47e309f72c8        6 days ago          372MB
portainer/portainer   latest              89c72b64ab63        12 days ago         74.2MB
wordpress             latest              6e880d17852f        2 weeks ago         420MB
mysql                 5.7.22              6bb891430fb6        6 months ago        372MB
ipple1986/hexo        latest              8eb73a3f4772        20 months ago       427MB
[root@zft tomcat]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                    NAMES
ae2aff6daf2d        ipple1986/hexo        "hexo server"            35 hours ago        Up 35 hours         0.0.0.0:4000->4000/tcp   some-hexo
cb5b22e06aa5        mysql:5.7.22          "docker-entrypoint.s…"   3 days ago          Up 3 days           0.0.0.0:3306->3306/tcp   mysql
29ff54b3124a        wordpress             "docker-entrypoint.s…"   3 days ago          Up 3 days           0.0.0.0:80->80/tcp       wordpress
c27ece8ced80        portainer/portainer   "/portainer"             7 days ago          Up 7 days           0.0.0.0:9000->9000/tcp   brave_snyder
[root@zft tomcat]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                     PORTS                    NAMES
1878c9f4985b        8b604d034978          "bash"                   9 minutes ago       Exited (0) 8 minutes ago                            elegant_goldberg
ae2aff6daf2d        ipple1986/hexo        "hexo server"            35 hours ago        Up 35 hours                0.0.0.0:4000->4000/tcp   some-hexo
cb5b22e06aa5        mysql:5.7.22          "docker-entrypoint.s…"   3 days ago          Up 3 days                  0.0.0.0:3306->3306/tcp   mysql
29ff54b3124a        wordpress             "docker-entrypoint.s…"   3 days ago          Up 3 days                  0.0.0.0:80->80/tcp       wordpress
c27ece8ced80        portainer/portainer   "/portainer"             7 days ago          Up 7 days                  0.0.0.0:9000->9000/tcp   brave_snyder
[root@zft tomcat]# docker rm 1878c9f4985b
1878c9f4985b
[root@zft tomcat]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
mytomcat              latest              3c0cca79ebb6        4 minutes ago       463MB
<none>                <none>              8b604d034978        11 minutes ago      463MB
tomcat                latest              168588387c68        3 days ago          463MB
mysql                 5.7.25              e47e309f72c8        6 days ago          372MB
portainer/portainer   latest              89c72b64ab63        12 days ago         74.2MB
wordpress             latest              6e880d17852f        2 weeks ago         420MB
mysql                 5.7.22              6bb891430fb6        6 months ago        372MB
ipple1986/hexo        latest              8eb73a3f4772        20 months ago       427MB
[root@zft tomcat]# docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Deleted Images:
deleted: sha256:8b604d0349781c00ef92b78d3f4f9c44dd2048bfd26ebe2b79132397161157b5
deleted: sha256:6d8df8a3c4bb1cc91465c1e0362e3ea5fdaa4a1b3b2826dd992e6f9931751c4d

Total reclaimed space: 13B
[root@zft tomcat]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
mytomcat              latest              3c0cca79ebb6        5 minutes ago       463MB
tomcat                latest              168588387c68        3 days ago          463MB
mysql                 5.7.25              e47e309f72c8        6 days ago          372MB
portainer/portainer   latest              89c72b64ab63        12 days ago         74.2MB
wordpress             latest              6e880d17852f        2 weeks ago         420MB
mysql                 5.7.22              6bb891430fb6        6 months ago        372MB
ipple1986/hexo        latest              8eb73a3f4772        20 months ago       427MB
[root@zft tomcat]# docker run -p 8080:8080 mytomcat
12-Feb-2019 10:00:43.514 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.38
12-Feb-2019 10:00:43.517 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Feb 5 2019 11:42:42 UTC
12-Feb-2019 10:00:43.518 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.38.0
12-Feb-2019 10:00:43.518 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
12-Feb-2019 10:00:43.518 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-957.el7.x86_64
12-Feb-2019 10:00:43.518 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
12-Feb-2019 10:00:43.518 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-8-openjdk-amd64/jre
12-Feb-2019 10:00:43.519 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_181-8u181-b13-2~deb9u1-b13
12-Feb-2019 10:00:43.519 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
12-Feb-2019 10:00:43.519 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
12-Feb-2019 10:00:43.519 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
12-Feb-2019 10:00:43.529 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
12-Feb-2019 10:00:43.530 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
12-Feb-2019 10:00:43.530 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
12-Feb-2019 10:00:43.530 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
12-Feb-2019 10:00:43.530 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
12-Feb-2019 10:00:43.530 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
12-Feb-2019 10:00:43.530 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
12-Feb-2019 10:00:43.530 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
12-Feb-2019 10:00:43.531 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
12-Feb-2019 10:00:43.531 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.21] using APR version [1.5.2].
12-Feb-2019 10:00:43.531 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
12-Feb-2019 10:00:43.531 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
12-Feb-2019 10:00:43.569 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.0j  20 Nov 2018]
12-Feb-2019 10:00:43.883 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
12-Feb-2019 10:00:43.984 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
12-Feb-2019 10:00:44.026 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
12-Feb-2019 10:00:44.045 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
12-Feb-2019 10:00:44.047 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1904 ms
12-Feb-2019 10:00:44.119 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
12-Feb-2019 10:00:44.119 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.38
12-Feb-2019 10:00:44.182 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/ROOT]
12-Feb-2019 10:00:45.269 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/ROOT] has finished in [1,086] ms
12-Feb-2019 10:00:45.269 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/docs]
12-Feb-2019 10:00:45.334 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/docs] has finished in [64] ms
12-Feb-2019 10:00:45.334 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/examples]
12-Feb-2019 10:00:46.280 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/examples] has finished in [945] ms
12-Feb-2019 10:00:46.280 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/host-manager]
12-Feb-2019 10:00:46.376 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/host-manager] has finished in [96] ms
12-Feb-2019 10:00:46.377 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/manager]
12-Feb-2019 10:00:46.482 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/manager] has finished in [105] ms
12-Feb-2019 10:00:46.504 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
12-Feb-2019 10:00:46.532 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
12-Feb-2019 10:00:46.541 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 2493 ms

结果展示

上下文环境


Last login: Tue Feb 12 17:29:27 2019 from 192.168.17.1
[root@zft ~]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                    NAMES
ae2aff6daf2d        ipple1986/hexo        "hexo server"            36 hours ago        Up 36 hours         0.0.0.0:4000->4000/tcp   some-hexo
cb5b22e06aa5        mysql:5.7.22          "docker-entrypoint.s…"   3 days ago          Up 3 days           0.0.0.0:3306->3306/tcp   mysql
29ff54b3124a        wordpress             "docker-entrypoint.s…"   3 days ago          Up 3 days           0.0.0.0:80->80/tcp       wordpress
c27ece8ced80        portainer/portainer   "/portainer"             7 days ago          Up 7 days           0.0.0.0:9000->9000/tcp   brave_snyder
[root@zft ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
mytomcat              latest              3c0cca79ebb6        42 minutes ago      463MB
tomcat                latest              168588387c68        3 days ago          463MB
mysql                 5.7.25              e47e309f72c8        6 days ago          372MB
portainer/portainer   latest              89c72b64ab63        12 days ago         74.2MB
wordpress             latest              6e880d17852f        2 weeks ago         420MB
mysql                 5.7.22              6bb891430fb6        6 months ago        372MB
ipple1986/hexo        latest              8eb73a3f4772        20 months ago       427MB
[root@zft ~]# cd /usr/local/docker/
[root@zft docker]# ls
tomcat
[root@zft docker]# ll
总用量 0
drwxr-xr-x. 2 root root 24 2月  12 17:53 tomcat
[root@zft docker]# cd tomcat/
[root@zft tomcat]# ll
总用量 4
-rw-r--r--. 1 root root 133 2月  12 17:53 Dockerfile
[root@zft tomcat]# vi test.html
测试docker build -t mytomcat . 上下文环境
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"test.html" [New] 1L, 49C written
[root@zft tomcat]# ll
总用量 8
-rw-r--r--. 1 root root 133 2月  12 17:53 Dockerfile
-rw-r--r--. 1 root root  49 2月  12 18:38 test.html
[root@zft tomcat]# docker build -t mytomcat
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile
[root@zft tomcat]# docker build -t mytomcat .
Sending build context to Docker daemon  3.072kB
Step 1/4 : FROM tomcat
 ---> 168588387c68
Step 2/4 : WORKDIR /usr/local/tomcat/webapps/ROOT/
 ---> Using cache
 ---> 48fd897834d6
Step 3/4 : RUN rm -rf *
 ---> Using cache
 ---> 26f9f86285b5
Step 4/4 : RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html
 ---> Using cache
 ---> 3c0cca79ebb6
Successfully built 3c0cca79ebb6
Successfully tagged mytomcat:latest
[root@zft tomcat]# docker run -it --rm mytomcat bash
root@70f6731ec410:/usr/local/tomcat/webapps/ROOT# ll
bash: ll: command not found
root@70f6731ec410:/usr/local/tomcat/webapps/ROOT# ls -a
.  ..  index.html
root@70f6731ec410:/usr/local/tomcat/webapps/ROOT# exit
exit
[root@zft tomcat]# ll
总用量 8
-rw-r--r--. 1 root root 133 2月  12 17:53 Dockerfile
-rw-r--r--. 1 root root  49 2月  12 18:38 test.html
[root@zft tomcat]# 
[root@zft tomcat]# vi Dockerfile 
WORKDIR /usr/local/tomcat/webapps/ROOT/
FROM tomcat
WORKDIR /usr/local/tomcat/webapps/ROOT/
RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"Dockerfile" 3L, 120C written
[root@zft tomcat]# docker build -t mytomcat .
Sending build context to Docker daemon  3.072kB
Step 1/3 : FROM tomcat
 ---> 168588387c68
Step 2/3 : WORKDIR /usr/local/tomcat/webapps/ROOT/
 ---> Using cache
 ---> 48fd897834d6
Step 3/3 : RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html
 ---> Running in 108da695e624
Removing intermediate container 108da695e624
 ---> b0060d8a60f4
Successfully built b0060d8a60f4
Successfully tagged mytomcat:latest
[root@zft tomcat]# docker run -it --rm mytomcat bash
root@732c1af84b00:/usr/local/tomcat/webapps/ROOT# ls -a
.   RELEASE-NOTES.txt  asf-logo-wide.svg  bg-middle.png    bg-nav.png    favicon.ico  index.jsp         tomcat.css  tomcat.png
..  WEB-INF            bg-button.png      bg-nav-item.png  bg-upper.png  index.html   tomcat-power.gif  tomcat.gif  tomcat.svg
root@732c1af84b00:/usr/local/tomcat/webapps/ROOT# ls
RELEASE-NOTES.txt  asf-logo-wide.svg  bg-middle.png    bg-nav.png    favicon.ico  index.jsp         tomcat.css  tomcat.png
WEB-INF            bg-button.png      bg-nav-item.png  bg-upper.png  index.html   tomcat-power.gif  tomcat.gif  tomcat.svg
root@732c1af84b00:/usr/local/tomcat/webapps/ROOT# ll
bash: ll: command not found
root@732c1af84b00:/usr/local/tomcat/webapps/ROOT# ls -al
total 192
drwxr-xr-x. 1 root root    24 Feb 12 10:40 .
drwxr-xr-x. 1 root root    18 Feb  5 11:44 ..
-rw-r--r--. 1 root root  7142 Feb  5 11:45 RELEASE-NOTES.txt
drwxr-xr-x. 2 root root    21 Feb  9 02:08 WEB-INF
-rw-r--r--. 1 root root 27235 Feb  5 11:45 asf-logo-wide.svg
-rw-r--r--. 1 root root   713 Feb  5 11:44 bg-button.png
-rw-r--r--. 1 root root  1918 Feb  5 11:44 bg-middle.png
-rw-r--r--. 1 root root  1392 Feb  5 11:44 bg-nav-item.png
-rw-r--r--. 1 root root  1401 Feb  5 11:44 bg-nav.png
-rw-r--r--. 1 root root  3103 Feb  5 11:44 bg-upper.png
-rw-r--r--. 1 root root 21630 Feb  5 11:44 favicon.ico
-rw-r--r--. 1 root root    13 Feb 12 10:40 index.html
-rw-r--r--. 1 root root 12290 Feb  5 11:45 index.jsp
-rw-r--r--. 1 root root  2376 Feb  5 11:44 tomcat-power.gif
-rw-r--r--. 1 root root  5581 Feb  5 11:45 tomcat.css
-rw-r--r--. 1 root root  2066 Feb  5 11:44 tomcat.gif
-rw-r--r--. 1 root root  5103 Feb  5 11:44 tomcat.png
-rw-r--r--. 1 root root 67795 Feb  5 11:45 tomcat.svg
root@732c1af84b00:/usr/local/tomcat/webapps/ROOT# exit
exit
[root@zft tomcat]# ll
总用量 8
-rw-r--r--. 1 root root 120 2月  12 18:40 Dockerfile
-rw-r--r--. 1 root root  49 2月  12 18:38 test.html
[root@zft tomcat]# vi Dockerfile 

FROM tomcat
WORKDIR /usr/local/tomcat/webapps/ROOT/
RUN rm -rf *
COPY test.html /usr/local/tomcat/webapps/ROOT/
RUN echo "hello docker" > /usr/local/tomcat/webapps/ROOT/index.html
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"Dockerfile" 5L, 180C written
[root@zft tomcat]# docker build -t mytomcat .
Sending build context to Docker daemon  3.072kB
Step 1/5 : FROM tomcat
 ---> 168588387c68
Step 2/5 : WORKDIR /usr/local/tomcat/webapps/ROOT/
 ---> Using cache
 ---> 48fd897834d6
Step 3/5 : RUN rm -rf *
 ---> Using cache
 ---> 26f9f86285b5
Step 4/5 : COPY test.html /usr/local/tomcat/webapps/ROOT/
 ---> 21a2101ffdde
Step 5/5 : RUN echo "hello docker" > /usr/local/tomcat/webapps/ROOT/index.html
 ---> Running in ce794f2112b5
Removing intermediate container ce794f2112b5
 ---> 0d76c7daa9b4
Successfully built 0d76c7daa9b4
Successfully tagged mytomcat:latest
[root@zft tomcat]# docker run -it --rm mytomcat bash
root@22a13604a4d6:/usr/local/tomcat/webapps/ROOT# ls -al
total 8
drwxr-xr-x. 1 root root 24 Feb 12 10:46 .
drwxr-xr-x. 1 root root 18 Feb  5 11:44 ..
-rw-r--r--. 1 root root 13 Feb 12 10:46 index.html
-rw-r--r--. 1 root root 49 Feb 12 10:38 test.html
root@22a13604a4d6:/usr/local/tomcat/webapps/ROOT# cat index.html 
hello docker
root@22a13604a4d6:/usr/local/tomcat/webapps/ROOT# cat test.html 
测试docker build -t mytomcat . 上下文环境
root@22a13604a4d6:/usr/local/tomcat/webapps/ROOT# 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,547评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,399评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,428评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,599评论 1 274
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,612评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,577评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,941评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,603评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,852评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,605评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,693评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,375评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,955评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,936评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,172评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,970评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,414评论 2 342

推荐阅读更多精彩内容