帮助命令
1、docker version #显示docker版本信息
2、docker info #显示docker的系统信息,包括镜像和容器数量
3、docker --help #帮助命令
帮助文档地址:
https://docs.docker.com/engine/reference/commandline/
镜像命令:
docker images 查看所有本地的主机上的镜像
[root@liuyang ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 300e315adb2f 2 months ago 209MB
hello-world latest bf756fb1ae65 14 months ago 13.3kB
#解释
REPOSITORY 镜像的仓库源
TAG 镜像的标签
IMAGE ID 镜像的ID
CREATED 镜像的创建时
SIZE 镜像大小
#可选项
-a --all 查看所有镜像
-q --quiet 只显示镜像ID
docker search搜索镜像
[root@liuyang ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 10565 [OK]
mariadb MariaDB Server is a high performing open sou… 3947 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 774 [OK]
percona Percona Server is a fork of the MySQL relati… 527 [OK]
#可选项
通过条件过滤:
--filter=STARS=3000 #搜索出来结果的stars大于3000的
docker pull 下载镜像
#下载镜像 docker pull 镜像名[:tag]
[root@liuyang ~]# docker pull mysql
//不写tag 默认最新版本latest
Using default tag: latest
latest: Pulling from library/mysql
//分层下载,docker image的核心 联合文件系统
a076a628af6f: Pull complete
f6c208f3f991: Pull complete
88a9455a9165: Pull complete
406c9b8427c6: Pull complete
7c88599c0b25: Pull complete
25b5c6debdaf: Pull complete
43a5816f1617: Pull complete
1a8c919e89bf: Pull complete
9f3cf4bd1a07: Pull complete
80539cea118d: Pull complete
201b3cad54ce: Pull complete
944ba37e1c06: Pull complete
//签名
Digest: sha256:feada149cb8ff54eade1336da7c1d080c4a1c7ed82b5e320efb5beebed85ae8c
Status: Downloaded newer image for mysql:latest
//真实地址
docker.io/library/mysql:latest
**docker.io/library/mysql:latest等价于docker pull mysql**
额外,我们说一下docker的联合文件系统,例如我们下载一个mysql5.7:
[root@liuyang ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
a076a628af6f: Already exists
f6c208f3f991: Already exists
88a9455a9165: Already exists
406c9b8427c6: Already exists
7c88599c0b25: Already exists
25b5c6debdaf: Already exists
43a5816f1617: Already exists
1831ac1245f4: Pull complete
37677b8c1f79: Pull complete
27e4ac3b0f6e: Pull complete
7227baa8c445: Pull complete
Digest: sha256:b3d1eff023f698cd433695c9506171f0d08a8f92a0c8063c1a4d9db9a55808df
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
我们可以看到,下载mysql5.7时,有一部分的文件被共用,减少了内存;
删除镜像:
docker rmi -f [image_id] 删除指定
docker rmi -f [image_id] [image_id] [image_id] [image_id] 删除多个
docker rmi -f$(docker images -aq) 删除所有
注:image_id能代表唯一标识即可,输三位也行
[root@liuyang ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 a70d36bc331a 6 weeks ago 449MB
mysql latest c8562eaf9d81 6 weeks ago 546MB
centos latest 300e315adb2f 2 months ago 209MB
hello-world latest bf756fb1ae65 14 months ago 13.3kB
[root@liuyang ~]# docker rmi -f bf756fb
Untagged: hello-world:latest
Untagged: hello-world@sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
[root@liuyang ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 a70d36bc331a 6 weeks ago 449MB
mysql latest c8562eaf9d81 6 weeks ago 546MB
centos latest 300e315adb2f 2 months ago 209MB