Docker的常用命令
Docker的常用命令
帮助命令
docker version # 显示 docker 的版本信息
docker info # 显示 docker 的系统信息,包括镜像和容器数量
docker 命令 --help
帮助文档的地址:https://docs.docker.com/engine/reference/commandline
镜像命令
docker images 查看所有本地的主机上的镜像
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all # Show all images (default hides intermediate images)
--digests # Show digests
-f, --filter filter # Filter output based on conditions provided
--format string # Pretty-print images using a Go template
--no-trunc # Don't truncate output
-q, --quiet # Only show image IDs
[lixun@aliecs ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
# 解释
REPOSITORY # 镜像的仓库源
TAG # 镜像的标签
IMAGE ID # 镜像的ID
CREATED # 镜像的创建时间
SIZE # 镜像的大小
docker search 搜索镜像
Usage: docker search [OPTIONS] TERM
Search the Docker Hub for images
Options:
-f, --filter filter # Filter output based on conditions provided
--format string # Pretty-print search using a Go template
--limit int # Max number of search results (default 25)
--no-trunc # Don't truncate output
[lixun@aliecs ~]$ sudo docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 12013 [OK]
mariadb MariaDB Server is a high performing open sou… 4603 [OK]
docker pull 下载镜像
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Pull an image or a repository from a registry
Options:
-a, --all-tags # Download all tagged images in the repository
--disable-content-trust # Skip image verification (default true)
--platform string # Set platform if server is multi-platform capable
-q, --quiet # Suppress verbose output
[lixun@aliecs ~]$ sudo docker pull mysql
Using default tag: latest # 不指定 tag,默认 latest
latest: Pulling from library/mysql
72a69066d2fe: Pull complete # 分层下载,docker images 的核心 联合文件系统
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
e5c707858ec0: Pull complete
fc41578cbf60: Pull complete
4785d896ef10: Pull complete
7d250cdc93be: Pull complete
309700f41983: Pull complete
45fd33301836: Pull complete
92f970c68b71: Pull complete
bb3544339a9e: Pull complete
f66ddf4c43fa: Pull complete
Digest: sha256:d0507b008897c39f6cbc76285af1171d4551988475e00e91344060023cd9c553 # 签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest # 真实地址
#
docker pull mysql ↔ docker pull docker.io/library/mysql:latest
# 指定 tag
[lixun@aliecs ~]$ sudo docker pull mysql:5.7
5.7: Pulling from library/mysql
72a69066d2fe: Already exists
93619dbc5b36: Already exists
99da31dd6142: Already exists
e5c707858ec0: Already exists
fc41578cbf60: Already exists
4785d896ef10: Already exists
7d250cdc93be: Already exists
2efe6ef3579a: Pull complete
40dc4a5ca43a: Pull complete
cd6f90222f59: Pull complete
031e631e9021: Pull complete
Digest: sha256:66480693e01295d85954bb5dbe2f41f29ebceb57d3d8098ea0c9d201473f2d8b
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
docker rmi 删除镜像
Usage: docker rmi [OPTIONS] IMAGE [IMAGE...]
Remove one or more images
Options:
-f, --force # Force removal of the image
--no-prune # Do not delete untagged parents
[lixun@aliecs ~]$ docker rmi -f 42f82e150ec2 # 删除指定
[lixun@aliecs ~]$ docker rmi -f 42f82e150ec2 feb5d9fea6a5 # 删除多个
[lixun@aliecs ~]$ docker rmi -f $(dcoker images -aq) # 删除所有容器