docker的常用命令
大家现在是抹零两可的
帮助命令
docker version # 显示docker 版本信息
docker info # 显示docker的系统信息,包括机镜像和容器的数量 更加详细的信息
docker --help # 帮助命令
帮助文档的地址
```https://docs.docker.com/reference/
镜像命令和容器命令学会了连入门都不算
镜像命令
docker images 查看所有本地主机上的镜像
[root@iz8g9301trfnpxz /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 6 months ago 13.3kB
[root@iz8g9301trfnpxz /]#
#
# 解释
# REPOSITORY 镜像的仓库源
# TAG 镜像的标签
# IMAGE ID 镜像的ID
# CREATED 镜像的创建时间
# SIZE 镜像的大小
# 可选项
-a , --all # 列出所有镜像
-q , --quiet # 只显示镜像的id
[root@iz8g9301trfnpxz /]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 6 months ago 13.3kB
[root@iz8g9301trfnpxz /]# docker images -q
bf756fb1ae65
[root@iz8g9301trfnpxz /]#
docker search 搜素
[root@iz8g9301trfnpxz /]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 9780 [OK]
mariadb MariaDB is a community-developed fork of MyS… 3569 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 717 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 78
[root@iz8g9301trfnpxz /]# docker search --help
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
[root@iz8g9301trfnpxz /]#
比如这样
[root@iz8g9301trfnpxz /]# docker search mysql --filter=STARS=5000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 9780 [OK]
docker pull 下载镜像
[root@iz8g9301trfnpxz /]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
6ec8c9369e08: Pull complete
177e5de89054: Pull complete
ab6ccb86eb40: Pull complete
e1ee78841235: Pull complete # 分层下载,docker image的核心 联合文件系统
09cd86ccee56: Pull complete
78bea0594a44: Pull complete
caf5f529ae89: Pull complete
cf0fc09f046d: Pull complete
4ccd5b05a8f6: Pull complete
76d29d8de5d4: Pull complete
8077a91f5d16: Pull complete
922753e827ec: Pull complete
Digest: sha256:fb6a6a26111ba75f9e8487db639bc5721d4431beba4cd668a4e922b8f8b14acc # 签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest # 真实地址
如果不写版本 默认最新
docker pull mysql
docker pull docker.io/library/mysql:latest
这两个命令是等价的
指定版本下载
[root@iz8g9301trfnpxz /]# docker pull mysql:5.7
5.7: Pulling from library/mysql
6ec8c9369e08: Already exists
177e5de89054: Already exists
ab6ccb86eb40: Already exists
e1ee78841235: Already exists
09cd86ccee56: Already exists
78bea0594a44: Already exists
caf5f529ae89: Already exists
4e54a8bcf566: Pull complete
50c21ba6527b: Pull complete
68e74bb27b39: Pull complete
5f13eadfe747: Pull complete
Digest: sha256:97869b42772dac5b767f4e4692434fbd5e6b86bcb8695d4feafb52b59fe9ae24
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
分层下载的好处是前面的可以共用
linux的联合文件系统
现在再查看一下
[root@iz8g9301trfnpxz /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 8679ced16d20 7 days ago 448MB
mysql latest e3fcc9e1cc04 7 days ago 544MB
hello-world latest bf756fb1ae65 6 months ago 13.3kB
[root@iz8g9301trfnpxz /]#
删除镜像
docker rmi -f imageid # 删除指定的image
docker rmi -f imageid imageid # 删除指定的多个image
docker rmi -f $(docker images -aq) # 删除全部容器
试一下
[root@iz8g9301trfnpxz /]# docker rmi -f 8679ced16d20
Untagged: mysql:5.7
Untagged: mysql@sha256:97869b42772dac5b767f4e4692434fbd5e6b86bcb8695d4feafb52b59fe9ae24
Deleted: sha256:8679ced16d206961b35686895b06cfafefde87ef02b518dfc2133081ebf47cda
Deleted: sha256:355f87dc5125a32cc35898a4dde17fb067585bc0d86704b5a467c0ccc0eea484
Deleted: sha256:8299d5c38042216210125535adb2600e46268a0e2b9ec799d12ea5b770236e79
Deleted: sha256:07311a303b2c7cf2ac6992aaf68e12326fe7255985166939cbab7d18b10e0f47
Deleted: sha256:306c9bc1ce2997d000bb6f1ea4108420d9752df93ce39164b7a2f876b954afc4
删除多个
批量删除全部
[root@iz8g9301trfnpxz /]# docker rmi -f $(docker images -aq)
Untagged: mysql:latest
Untagged: mysql@sha256:fb6a6a26111ba75f9e8487db639bc5721d4431beba4cd668a4e922b8f8b14acc
Deleted: sha256:e3fcc9e1cc046c92cfcea0d66cdb00fcb7747e87dde96dfc958bd80be37af117
Deleted: sha256:7a1c5c1a40dad78bacb211ec3d7918acdd78a76185fd33a167260c3e51e97fa4
Deleted: sha256:abb5f0f890ba2f327d30b5ca1bbc35584bc6357c8d6f4bdc2e4637cce2ea9a35
Deleted: sha256:919c56fc8230b0ddf8580e0a58d34ae1c5e48069d9b48cc41ae7a1cae82bb60e
Deleted: sha256:962d6891622cf4a7e8932f6c76b2c2f3ab9cecb8aad71d55adacc2aece6b0181
Deleted: sha256:ab26019b1328bff5ea5132b5e3f52b9fd3808e734f1a39141fb9e5da561200e2
Deleted: sha256:06bd523b11319c8177ab2003cb31b296cea22b0201bf8ae987ac300118a0654f
Deleted: sha256:a8681d5c66889e97303be147d30eb8ec4b0bd5bc0e2c774b4d94f52ec23c4649
Deleted: sha256:c28ab987d3964139dcd3852e1c10ef0a425d2705c71a3b68b411460279d8535d
Deleted: sha256:c0fc32d1072662668dd59842d893e5ee125c1958931ae84630132b7bb6c09198
Deleted: sha256:da0ebf91b8bc2d545dbe73cbf9b7c7b25df71033f5057133a445e9c33a36ec7d
Deleted: sha256:483d8f607b803b5e3d3f97adbad3b0e692670f223b2529ecae5d04888c29ad5d
Deleted: sha256:95ef25a3204339de1edf47feaa00f60b5ac157a498964790c58c921494ce7ffd
Untagged: hello-world:latest
Untagged: hello-world@sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
[root@iz8g9301trfnpxz /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE