一、查看镜像列表

[root@VM_0_8_centos test]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test/ubuntu v1 e76cc2165488 22 hours ago 73.9MB
ubuntu latest adafef2e596e 2 weeks ago 73.9MB
ubuntu 15.10 9b9cb95443b5 4 years ago 137MB
training/webapp latest 6fae60ef3446 5
  • REPOSITORY:表示镜像的仓库源
  • TAG:镜像的标签
  • IMAGE ID:镜像ID
  • CREATED:镜像创建时间
  • SIZE:镜像大小

        同一仓库源可以有多个 TAG,代表这个仓库源的不同版本。我们用 REPOSITORY:TAG 来定义不同的镜像。如果你不指定一个镜像的版本标签,例如你只使用 ubuntu,docker 将默认使用 ubuntu:latest 镜像。

二、获取新的镜像

[root@VM_0_8_centos test]# docker pull ubuntu:13.10
13.10: Pulling from library/ubuntu
Image docker.io/library/ubuntu:13.10 uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/
a3ed95caeb02: Pull complete
0d8710fc57fd: Pull complete
5037c5cd623d: Pull complete
83b53423b49f: Pull complete
e9e8bd3b94ab: Pull complete
7db00e6b6e5e: Pull complete
Digest: sha256:403105e61e2d540187da20d837b6a6e92efc3eb4337da9c04c191fb5e28c44dc
Status: Downloaded newer image for ubuntu:13.10
docker.io/library/ubuntu:13.10
[root@VM_0_8_centos test]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test/ubuntu v1 e76cc2165488 23 hours ago 73.9MB
ubuntu latest adafef2e596e 2 weeks ago 73.9MB
ubuntu 15.10 9b9cb95443b5 4 years ago 137MB
training/webapp latest 6fae60ef3446 5 years ago 349MB
ubuntu 13.10 7f020f7bf345 6

三、查找镜像

        通过​​https://hub.docker.com/​​可以搜索镜像,也可以使用 DOCKER search 命令搜索镜像:

[root@VM_0_8_centos test]# docker search webapp
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
training/webapp 76 [OK]
kodekloud/webapp-color 2
careapp/webapp-admin The admin web app in ReactJS 2
kodekloud/webapp-delayed-start 1
kodekloud/webapp-conntest 1
scottyc/webapp A demo web app used for the Kubernetes secur… 0 [OK]
croudtech/webapp Croudtech webapp 0 [OK]
arungupta/webapp 0
adeq2019/webapp 0
thinkservice/webapp-compiler 0
busappbackendappknit/webapp 0
envirocar/webapp 0
beatboxapp/webapp 0
vrhood/webapp-frontend 0
vrhood/webapp-backend 0
itherz/webapp-full PHP-FPM + nginx + ssh image for full develop… 0 [OK]
quorumintegration/webapp webapp 0 [OK]
opentargets/webapp targetvalidation.org angular webapp 0 [OK]
esrahofstede/webapplication Sample .net webapp 0
laticinio/webapp Laticin Webapp 0 [OK]
thetaiter/webapp-example webapp-example 0
dock0/webapp Web application with nginx proxying requests… 0 [OK]
wrmarchetto/webapp Webapp 0 [OK]
pluvinel/webapp Pluvinel webapp 0
corba/webapp.dataop Database Operations webapp. 0
  • NAME: 镜像仓库源的名称
  • DESCRIPTION: 镜像的描述
  • OFFICIAL: 是否 docker 官方发布
  • stars: 类似 Github 里面的 star,表示点赞、喜欢的意思。
  • AUTOMATED: 自动构建。

四、删除镜像

[root@VM_0_8_centos test]# docker rmi 7f020f7bf345
Untagged: ubuntu:13.10
Untagged: ubuntu@sha256:403105e61e2d540187da20d837b6a6e92efc3eb4337da9c04c191fb5e28c44dc
Deleted: sha256:7f020f7bf34554411031ec0d4f2ab46a2976dad403e1c26bc21dc1bf4c48c8aa
Deleted: sha256:2aac093d13faafda4d0da3534d30274bcc4e5475b1e126c84b9d670862f5e4ef
Deleted: sha256:c676fe3dd3ceb6442e8b23350de88adc6546a52f75bd92dbb1a789b7c6de0fcf
Deleted: sha256:7c6a37fb8fe6a41aaf7c6c7a2cc3d448c01df026b2056a9f35e490e7bf6285cc
Deleted: sha256:b0e8be8278c28daa541ad564fc91dbea99263caa6e5e68db033061c5e08f0315
Deleted: sha256:78dcbd700c6678a7af4422e0ad516628852973a255526f4b617f33db218e1075
Deleted: sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
[root@VM_0_8_centos test]#

五、更新镜像

        在镜像容器内可以对镜像进行更新。

        查看现有的镜像:

[root@VM_0_8_centos ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
87c379cbba20 training/webapp "python app.py" 2 hours ago Up 2 hours 0.0.0.0:32771->5000/tcp dreamy_elbakyan
5e672688580a training/webapp "python app.py" 47 hours ago Exited (137) 5 hours ago sweet_hodgkin
9c646b56522a ubuntu "/bin/bash" 2 days ago Up 2

        进入 9c646b56522a 镜像容器,使用 apt-get update 命令更新镜像,完成之后使用 exit 命令退出镜像容器:

[root@VM_0_8_centos ~]# docker exec -it 9c646b56522a /bin/bash
root@9c646b56522a:/# apt-get update
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [111 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [187 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [98.3 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [38.7 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [51.3 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [1078 B]
Get:9 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:12 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [38.7 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [17.4 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [172 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [399 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [3209 B]
Fetched 14.3 MB in 47s (302 kB/s)
Reading package lists... Done
root@9c646b56522a:/# exit
exit

        提交容器副本:

[root@VM_0_8_centos ~]# docker commit -m='has update' -a='runoop' 9c646b56522a runoop/ubuntu:v2
sha256:30589a063f5daee6141a4e502ec37bf9c0c301e20ca2430e280d38ed98c3dbab
  • -m: 提交的描述信息
  • -a: 指定镜像作者
  • e218edb10161:容器 ID
  • runoob/ubuntu:v2: 指定要创建的目标镜像名

        查看新镜像 runoop/ubuntu:v2

[root@VM_0_8_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
runoop/ubuntu v2 30589a063f5d 37 seconds ago 96.4MB
test/ubuntu v1 e76cc2165488 24 hours ago 73.9MB
ubuntu latest adafef2e596e 2 weeks ago 73.9MB
ubuntu 15.10 9b9cb95443b5 4 years ago 137MB
training/webapp latest 6fae60ef3446 5

 

结束!