Docker常用命令合集--镜像操作命令

目录

1. docker search image_name

1.1 从镜像仓库查找所有包含hello-world的镜像
[root@myhost ~]# docker search hello-world
...
...
...
...

1.2 从镜像仓库查找所有包含hello-world的镜像,并且收藏数大于10的镜像
[root@myhost ~]# docker search -s 10 hello-world
...
...
...
...

2. docker pull image_name

2.1 从镜像仓库中拉取下载 REPOSITORY 为 hello-world 的镜像(默认是最新版本)
[root@myhost ~]# docker pull hello-world
Using default tag: latest
Trying to pull repository docker.io/library/hello-world ... 
latest: Pulling from docker.io/library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for docker.io/hello-world:latest

[root@myhost ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              d1165f221234        5 weeks ago         13.3 kB
2.2 从镜像仓库中拉取下载 REPOSITORY 为 hello-world所有镜像
[root@myhost ~]# docker pull -a hello-world
...
...
...
...

[root@myhost ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
...
...
...
...

3. docker images

3.1 docker images 列出或查看本地镜像
[root@myhost ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              d1165f221234        5 weeks ago         13.3 kB
3.2 docker images -a 列出本地所有的镜像(含中间映像层,默认情况下,过滤掉中间映像层)
[root@myhost ~]# docker  -a images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              d1165f221234        5 weeks ago         13.3 kB
3.3 docker images --digests 显示镜像的摘要信息
[root@myhost ~]# docker images --digests 
REPOSITORY              TAG                 DIGEST                                                                    IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24   d1165f221234        5 weeks ago         13.3 kB
3.4 docker images -f 显示满足条件的镜像(后面需跟条件参数)

3.5 docker images --format 指定返回值的模板文件(后面需跟模板参数)

3.6 docker images --no-trunc 显示完整的镜像信息
[root@myhost ~]# docker images --no-trunc
REPOSITORY              TAG                 IMAGE ID                                                                  CREATED             SIZE
docker.io/hello-world   latest              sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726   5 weeks ago         13.3 kB
3.7 docker images -q 只显示镜像ID
[root@myhost ~]# docker images -q
d1165f221234[root@myhost ~]# docker images -q
d1165f221234

4. docker rmi image_name/image_id

4.1 docker rmi image_name/image_id 删除本地没有被容器占用的镜像
[root@myhost ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              d1165f221234        5 weeks ago         13.3 kB

[root@myhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@myhost ~]# docker rmi d1165f221234 
Untagged: docker.io/hello-world:latest
Untagged: docker.io/hello-world@sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
Deleted: sha256:f22b99068db93900abe17f7f5e09ec775c2826ecfe9db961fea68293744144bd

[root@myhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

4.2 docker rmi image_name/image_id -f 强制删除本地镜像
[root@myhost ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              d1165f221234        5 weeks ago         13.3 kB

[root@myhost ~]# docker rmi d1165f221234
Error response from daemon: conflict: unable to delete d1165f221234 (must be forced) - image is being used by stopped container 2a1ef33ceb3f

注意:一个镜像如果关联某个或几个容器,是不能直接被删除的,必须先停止并删除所有相关容器之后才能够删除此镜像。
如果不先停止并删除所有相关容器,也可以使用 docker rmi image_name/image_id -f 命令来强制删除此镜像。

[root@myhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
2a1ef33ceb3f        d1165f221234        "/hello"            8 seconds ago       Exited (0) 7 seconds ago                       confident_roentgen

[root@myhost ~]# docker rmi d1165f221234 -f
Untagged: docker.io/hello-world:latest
Untagged: docker.io/hello-world@sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726

[root@myhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

[root@myhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                          PORTS               NAMES
2a1ef33ceb3f        d1165f221234        "/hello"            About a minute ago   Exited (0) About a minute ago                       confident_roentgen

4.3 docker rmi image_name/image_id --no-prune 不移除该镜像的过程镜像,默认移除
Status: Downloaded newer image for docker.io/hello-world:latest
[root@myhost ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              d1165f221234        5 weeks ago         13.3 kB

[root@myhost ~]# docker rmi d1165f221234 --no-prune
Untagged: docker.io/hello-world:latest
Untagged: docker.io/hello-world@sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
Deleted: sha256:f22b99068db93900abe17f7f5e09ec775c2826ecfe9db961fea68293744144bd

[root@myhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

5. docker push image_name

上传本地镜像myapache:v1到镜像仓库中
docker push myapache:v1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值