1: 镜像文件的查看
查看本地有哪些镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
nginx latest b7dd2c8cb8a8 9 days ago 108.6 MB
docker latest b4e0a2b00e9d 3 weeks ago 132.8 MB
hello-world latest 690d80202531 3 months ago 1.848 kB
nginx 1.9 0e181a348ded 21 months ago 182.7 MB
[root@localhost ~]#
2: 从docker hub中收索镜像
[root@localhost ~]# docker search tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementa... 1742 [OK]
dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba... 48 [OK]
tomee Apache TomEE is an all-Apache Java EE cert... 45 [OK]
davidcaste/alpine-tomcat Apache Tomcat 7/8 using Oracle Java 7/8 wi... 24 [OK]
consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 17 [OK]
cloudesire/tomcat Tomcat server, 6/7/8 15 [OK]
bitnami/tomcat Bitnami Tomcat Docker Image 10 [OK]
jeanblanchard/tomcat Minimal Docker image with Apache Tomcat 8
meirwa/spring-boot-tomcat-mysql-app a sample spring-boot app using tomcat and ... 8 [OK]
tutum/tomcat Base docker image to run a Tomcat applicat... 8
aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 6 [OK]
rightctrl/tomcat CentOS , Oracle Java, tomcat application s... 2 [OK]
camptocamp/tomcat-logback Docker image for tomcat with logback integ... 1 [OK]
maluuba/tomcat7-java8 Tomcat7 with java8. 1
primetoninc/tomcat Apache tomcat 8.5, 8.0, 7.0 1 [OK]
99taxis/tomcat7 Tomcat7 1 [OK]
picoded/tomcat7 tomcat7 with jre8 and MANAGER_USER / MANAG... 0 [OK]
s390x/tomcat Apache Tomcat is an open source implementa... 0
fabric8/tomcat-8 Fabric8 Tomcat 8 Image 0 [OK]
swisstopo/service-print-tomcat backend tomcat for service-print "the true... 0
awscory/tomcat tomcat 0
trollin/tomcat 0
hegand/tomcat docker-tomcat 0 [OK]
qminderapp/tomcat7 Tomcat 7 0
oobsri/tomcat8 Testing CI Jobs with different names. 0
[root@localhost ~]#
3: 从docker hub中收到的镜像文件中,获取镜像
[root@localhost ~]# docker pull tomcat
latest: Pulling from tomcat
bf25cd35f162: Pulling fs layer
5eba81ad5ca2: Pull complete
ef0054da8f65: Pull complete
0aa5736aa136: Pull complete
c2b907fc46a8: Pull complete
5cc9c515cd33: Pull complete
e9bd7b373665: Pull complete
63c9362eed15: Pull complete
96c461debf93: Pull complete
1d7bddba33ce: Pull complete
99c7f6d80f90: Pull complete
e285b2bee41a: Pull complete
00220c3dbebf: Pull complete
0299490abd11: Pull complete
4cec026973ac: Pull complete
4367fc8bf551: Pull complete
1254f856fb1d: Pull complete
ef12f3dc134f: Pull complete
af7b031bd605: Pull complete
fd58ae14a974: Pull complete
f5227197bf83: Pull complete
96e2732fe414: Pull complete
05ab404932f5: Pull complete
fd58b669262d: Pull complete
725717a375ef: Pull complete
e50e4341c94b: Pull complete
1562d06ff0d4: Pull complete
743127f801e6: Pull complete
55b788ea67a1: Pull complete
872dfc911239: Pull complete
4f2f1e2dd054: Pull complete
8dedd7622f09: Pull complete
d12eee4932cd: Pull complete
Digest: sha256:a09dbd59ce6326e3e9bd6dd9baa86427fd982f1501cab78ef68a9b20bca92247
Status: Downloaded newer image for tomcat:latest
[root@localhost ~]#
然后通过查看本地镜像就可以找到tomcat 镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
nginx latest b7dd2c8cb8a8 9 days ago 108.6 MB
tomcat latest d12eee4932cd 2 weeks ago 557.4 MB
docker latest b4e0a2b00e9d 3 weeks ago 132.8 MB
hello-world latest 690d80202531 3 months ago 1.848 kB
nginx 1.9 0e181a348ded 21 months ago 182.7 MB
[root@localhost ~]#
4: 更新镜像
更新镜像是需要先创建一个容器,然后在容器中通过apt-get update 进行更新,更新后,然后再通过docker commit 来提交容器副本
我们直接用以前创建的容器进行更新,使用CONTAINER ID为af8c2df7d378 进入容器
[root@localhost ~]# docker exec -it af8c2df7d378 /bin/bash
查看命令
root@af8c2df7d378:/# apt
apt apt-cdrom apt-get apt-mark
apt-cache apt-config apt-key
执行更新命令
root@af8c2df7d378:/# apt-get update
Get:1 http://security.debian.org stretch/updates InRelease [63.0 kB]
Ign:2 http://cdn-fastly.deb.debian.org/debian stretch InRelease
Get:3 http://cdn-fastly.deb.debian.org/debian stretch-updates InRelease [91.0 kB]
Get:5 http://security.debian.org stretch/updates/main amd64 Packages [418 kB]
Get:4 http://cdn-fastly.deb.debian.org/debian stretch Release [118 kB]
Get:6 http://cdn-fastly.deb.debian.org/debian stretch Release.gpg [2434 B]
Get:7 http://cdn-fastly.deb.debian.org/debian stretch-updates/main amd64 Packages [8431 B]
Get:8 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 Packages [9531 kB]
Fetched 10.2 MB in 2min 7s (80.3 kB/s)
Reading package lists... Done
root@af8c2df7d378:/#
创建镜像nginx:20180302_v2
[root@localhost ~]# docker commit -m="has update v2" -a="wuxu_test" af8c2df7d378 nginx:20180302_v2
324d282623d331a00f0fbca4921e5ecac7fa1814d94875329f2e0a95fcd6b490
[root@localhost ~]#
查询创建后的镜像nginx:20180302_v2
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
nginx 20180302_v2 324d282623d3 About a minute ago 124.7 MB
nginx latest b7dd2c8cb8a8 9 days ago 108.6 MB
<none> <none> e285b2bee41a 2 weeks ago 133.8 MB
docker latest b4e0a2b00e9d 3 weeks ago 132.8 MB
hello-world latest 690d80202531 3 months ago 1.848 kB
nginx 1.9 0e181a348ded 21 months ago 182.7 MB
[root@localhost ~]#
5: 使用镜像创建容器, 以更新的nginx:20180302_v2 为例,创建容器
[root@localhost ~]# docker run -d -p 80:80 nginx:20180302_v2
46046eaee29cea92a36935fad2a51c0694930caabfeed6093b028d3669c80d89
[root@localhost ~]#
创建容器后,进行检查查看
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46046eaee29c nginx:20180302_v2 "nginx -g 'daemon of 13 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp happy_pasteur
af8c2df7d378 nginx "nginx -g 'daemon of 10 hours ago Up 10 hours 0.0.0.0:8081->80/tcp elated_sammet
b35721c1678f nginx "nginx -g 'daemon of 10 hours ago Up 10 hours 0.0.0.0:8080->80/tcp focused_euclid
[root@localhost ~]# ^C