镜像使用
查找远程仓库镜像
[root@cvm-3hfmumc28a223 ~]# docker search java
-----
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
node Node.js is a JavaScript-based platform for s… 8898 [OK]
tomcat Apache Tomcat is an open source implementati… 2745 [OK]
openjdk OpenJDK is an open-source implementation of … 2282 [OK]
java Java is a concurrent, class-based, and objec… 1976 [OK]
ghost Ghost is a free and open source blogging pla… 1192 [OK]
couchdb CouchDB is a database that uses JSON for doc… 349 [OK]
jetty Jetty provides a Web server and javax.servle… 336 [OK]
groovy Apache Groovy is a multi-faceted language fo… 93 [OK]
ibmjava Official IBM® SDK, Java™ Technology Edition … 79 [OK]
lwieske/java-8 Oracle Java 8 Container - Full + Slim - Base… 46 [OK]
nimmis/java-centos This is docker images of CentOS 7 with diffe… 42 [OK]
从远程仓库拖取镜像
[root@cvm-3hfmumc28a223 ~]# docker pull java
-----
Using default tag: latest
latest: Pulling from library/java
5040bd298390: Pull complete
fce5728aad85: Pull complete
76610ec20bf5: Extracting 42.5MB
76610ec20bf5: Pull complete
60170fec2151: Pull complete
e98f73de8f0d: Pull complete
11f7af24ed9c: Pull complete
49e2d6393f32: Extracting [==================================================>] 130.1MB/130.1MB
查看本地镜像
[root@cvm-3hfmumc28a223 ~]# docker images
-----
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 1b6b1fe7261e 3 weeks ago 647MB
java latest d23bdf5b1b1b 3 years ago 643MB
删除本地镜像
[root@cvm-3hfmumc28a223 ~]# docker rmi tomcat
-----
Untagged: tomcat:latest
Untagged: tomcat@sha256:ce753be7b61d86f877fe5065eb20c23491f783f283f25f6914ba769fee57886b
Deleted: sha256:1b6b1fe7261ea2f94c5911ad04395cb8d05428cad39fa60e9fee556f79e9afc2
Deleted: sha256:ca00aa392edea436dadb8875411af316f01dda296f00e4131ad418b5d56778df
Deleted: sha256:59d2b91c7d8c9e30d7a9b95db1183f100222a65f62eecec852370b6360900b01
Deleted: sha256:b472f97c9d2f654fffd4bd1046b87be5c5c3ee78623dc8936486971e1fb6388f
容器使用
生成容器
[root@cvm-3hfmumc28a223 ~]# docker run -d --name tomcat -p 8081:8080 tomcat
-----
Unable to find image 'tomcat:latest' locally
latest: Pulling from library/tomcat
376057ac6fa1: Pull complete
5a63a0a859d8: Pull complete
496548a8c952: Pull complete
2adae3950d4d: Pull complete
0a297eafb9ac: Pull complete
09a4142c5c9d: Pull complete
9e78d9befa39: Pull complete
18f492f90b9c: Pull complete
7834493ec6cd: Pull complete
216b2be21722: Pull complete
Digest: sha256:ce753be7b61d86f877fe5065eb20c23491f783f283f25f6914ba769fee57886b
Status: Downloaded newer image for tomcat:latest
b94ff33ea43269de3af06cbd31f52939669b3f45010b34447dfa419d57fc7a7b
※容器端口 8080 绑定主机端口 8081。
查看已有容器
[root@cvm-3hfmumc28a223 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b94ff33ea432 tomcat "catalina.sh run" 2 minutes ago Up 2 minutes 0.0.0.0:8081->8080/tcp tomcat
进入容器
[root@cvm-3hfmumc28a223 ~]# docker exec -it tomcat /bin/bash
-----
root@b94ff33ea432:/usr/local/tomcat#
root@b94ff33ea432:/usr/local/tomcat# mv webapps webapps2
root@b94ff33ea432:/usr/local/tomcat# mv webapps.dist webapps
tomcat启动后,浏览器中输入 http://<docker主机IP地址>:8081
停止容器
[root@cvm-3hfmumc28a223 ~]# docker stop tomcat
tomcat
启动容器
[root@cvm-3hfmumc28a223 ~]# docker start tomcat
tomcat
删除容器
[root@cvm-3hfmumc28a223 ~]# docker rm tomcat
tomcat