docker的常用命令

帮助命令

docker version  # 显示docker的版本信息
docker info #显示docker的系统信息,包括镜像和容器的数量
docker 命令 --help #帮助命令

镜像命令

docker images 查看所有本地的主机上的镜像

[root@VM-0-16-centos ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    feb5d9fea6a5   3 weeks ago   13.3kB

# 解释
REPOSITORY 镜像的仓库源
TAG 镜像的标签
IMAGE ID 镜像的id
CREATED 镜像的创建时间
SIZE 镜像大小
# 可选项
  -a, --all             Show all images (显示所有的镜像)
  -q, --quiet           Only show image IDs(只显示镜像的id)

搜索命令

docker search

[root@VM-0-16-centos ~]# docker search mysql
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   11543     [OK]       
mariadb                           MariaDB Server is a high performing open sou…   4390      [OK]  
# 可选项,通过搜索过滤
--filter=STARS=3000 #搜索出来的镜像就是STARS大于3000的
[root@VM-0-16-centos ~]# docker search mysql --filter=STARS=3000
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relation…   11543     [OK]       
mariadb   MariaDB Server is a high performing open sou…   4390      [OK]   

下载命令

docker pull [OPTIONS] 镜像名 [:TAG]

[root@VM-0-16-centos ~]# docker pull redis
Using default tag: latest  #如果不写tag(版本)默认就是latest(最新)
latest: Pulling from library/redis
7d63c13d9b9b: Pull complete #分层下载,docker image的核心 联合文件系统
a2c3b174c5ad: Pull complete 
283a10257b0f: Pull complete 
7a08c63a873a: Pull complete 
0531663a7f55: Pull complete 
9bf50efb265c: Pull complete 
Digest: sha256:a89cb097693dd354de598d279c304a1c73ee550fbfff6d9ee515568e0c749cfe  #签名
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest #真实地址

#真实地址等价
docker pull redis
docker pull docker.io/library/redis:latest

#制定版本下载
查看版本地址:https://hub.docker.com/_/redis
docker pull redis:5.7
#制定版本下载
查看版本地址:https://hub.docker.com/_/redis
docker pull redis:5.0

[root@VM-0-16-centos ~]# docker pull redis:5.0
5.0: Pulling from library/redis
7d63c13d9b9b: Already exists 
a2c3b174c5ad: Already exists 
283a10257b0f: Already exists
54ac4e97e390: Pulling fs layer
0d3ede1e63a5: Pulling fs layer

删除命令

docker rmi -f 容器id #删除指定容器



[root@VM-0-16-centos ~]# docker images -a
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
redis         latest    7faaec683238   5 days ago    113MB
hello-world   latest    feb5d9fea6a5   3 weeks ago   13.3kB
[root@VM-0-16-centos ~]# docker rmi -f 7faaec683238
Untagged: redis:latest
Untagged: redis@sha256:a89cb097693dd354de598d279c304a1c73ee550fbfff6d9ee515568e0c749cfe
Deleted: sha256:7faaec68323851b2265bddb239bd9476c7d4e4335e9fd88cbfcc1df374dded2f
Deleted: sha256:e6deb90762475cda72e21895911f830ed99fd1cc6d920d92873270be91235274
Deleted: sha256:2649acad13241d9c8d81e49357bc66cce459b352ded7f423d70ede7bd3bb7b89

#删除所有容器
docker rmi -f $(docker iamges -aq)
[root@VM-0-16-centos ~]# docker rmi -f $(docker images -aq)
Untagged: hello-world:latest
Untagged: hello-world@sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
[root@VM-0-16-centos ~]# docker images -aq
[root@VM-0-16-centos ~]# 

循环
请先登录后发表评论
  • latest comments
  • 总共0条评论