Docker - docker 常用命令
帮助命令
镜像命令
容器命令
帮助命令
# 查看docker的版本信息
docker version
# 显示docker的系统信息,包括镜像和容器的数量
docker info
# 查看帮助信息(万能命令)
docker 命令 --help
更多命令可在官网查看:https://docs.docker.com/reference/
镜像命令
docker images 查看本地主机的所有镜像
[root@node01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 9c7a54a9a43c 2 weeks ago 13.3kB
# 解释
REPOSITORY 镜像的仓库源
TAG 镜像的标签
IMAGE ID 镜像的ID
CREATED 镜像的创建时间
SIZE 镜像的大小
# 可选项
-a, --all 列出所有的镜像
-q, --quiet 只显示镜像的ID
docker search xxx 在远程仓库搜索某个镜像
# 在远程仓库搜索mysql
docker search mysql
# 可选项,过滤镜像STARS大于10000的
[root@node01 ~]# docker search mysql --filter=STARS=10000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 14155 [OK]
[root@node01 ~]#
docker pull 下载镜像
# 下载mysql的镜像,默认下载最新版
[root@node01 ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
328ba678bf27: Pull complete
f3f5ff008d73: Pull complete
dd7054d6d0c7: Pull complete
70b5d4e8750e: Pull complete
cdc4a7b43bdd: Pull complete
a0608f8959e0: Pull complete
5823e721608f: Pull complete
a564ada930a9: Pull complete
539565d00e89: Pull complete
a11a06843fd5: Pull complete
92f6d4aa041d: Pull complete
Digest: sha256:a43f6e7e7f3a5e5b90f857fbed4e3103ece771b19f0f75880f767cf66bbb6577
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
[root@node01 ~]#
[root@node01 ~]#
# 指定版本下载镜像,注意远程仓库中要有该版本的镜像
[root@node01 ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
e83e8f2e82cc: Pull complete
0f23deb01b84: Pull complete
f5bda3b184ea: Pull complete
ed17edbc6604: Pull complete
33a94a6acfa7: Pull complete
f153bd2953e4: Pull complete
ab532edfb813: Pull complete
c76bdfe4f3d0: Pull complete
8a7ffe2f2551: Pull complete
857ada4fbbcc: Pull complete
b7c508404c3c: Pull complete
Digest: sha256:f57eef421000aaf8332a91ab0b6c96b3c83ed2a981c29e6528b21ce10197cd16
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
[root@node01 ~]#
[root@node01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 9c7a54a9a43c 2 weeks ago 13.3kB
mysql 5.7 dd6675b5cfea 5 weeks ago 569MB
mysql latest 8189e588b0e8 5 weeks ago 564MB
[root@node01 ~]#
# 可选项
docker rmi 删除镜像
[root@node01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 9c7a54a9a43c 2 weeks ago 13.3kB
mysql 5.7 dd6675b5cfea 5 weeks ago 569MB
mysql latest 8189e588b0e8 5 weeks ago 564MB
[root@node01 ~]#
[root@node01 ~]#
[root@node01 ~]#
[root@node01 ~]# docker rmi -f dd6675b5cfea
Untagged: mysql:5.7
Untagged: mysql@sha256:f57eef421000aaf8332a91ab0b6c96b3c83ed2a981c29e6528b21ce10197cd16
Deleted: sha256:dd6675b5cfea17abb655ea8229cbcfa5db9d0b041f839db0c24228c2e18a4bdf
Deleted: sha256:ce931a23976217d9a54389e972eb3fc823ec4c2ef51ff712f6330437bd7a373a
Deleted: sha256:64eb3560e160f706ef4994cb38a97d1ce32a219e547ead81fd51766d46c5e1c2
Deleted: sha256:9e009673657831f462ffdacbf099a070f0bb03cbb105483c69470a25ab87efe0
Deleted: sha256:a37428431f1f5ebda54ff32a40299e87a2e5e9b867bfb9c1e6199f9d04850a9a
Deleted: sha256:b5463af91376b3d4772113805dbce79805129326c301a80947cbfd43c8069898
Deleted: sha256:c0a975af561fdd0b68965ca9c572d91244b6dff6124b6a4d66b3188c0cb72d9f
Deleted: sha256:38700ee823d5d82b695bb7d553973c0106384a6984b553e2af6d6fb9545d9636
Deleted: sha256:7cfca860605c4f16b1f255ebd51e2c801e00ac16997c7840428f88a2246cfebb
Deleted: sha256:0d8a62cb129e3cebaaef51f977b670282775d48a9cdaa021a0cb5ed73243a446
Deleted: sha256:66e6e199acb7395ac9a10b125841eafdfa3f80a1a3f710e0a0a9519da228bce2
Deleted: sha256:e74a57638021cebbbe0dda98a27675f9b53258050ee2c29c3e5fb7fb1f3ab533
[root@node01 ~]#
[root@node01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 9c7a54a9a43c 2 weeks ago 13.3kB
mysql latest 8189e588b0e8 5 weeks ago 564MB
[root@node01 ~]#
# 删除所有镜像(递归删除)
docker rmi -f $(docker images -aq)
容器命令