docker

修改本地镜像标签:
不同标签的镜像 ID 完全一致,说明它们实际上指向了同一个镜像文件,只是别名不同而已。

[root@master system]# docker tag xindecommit xincon:nin
[root@master system]#
[root@master system]#
[root@master system]# docker images
REPOSITORY                                 TAG        IMAGE ID       CREATED          SIZE
xincon                                     nin        0a688bcee29f   27 seconds ago   2.37GB
xindecommit                                latest     0a688bcee29f   27 seconds ago   2.37GB

删除none容器镜像,释放空间
a、查看 中间镜像 :(属于对磁盘没有影响的 镜像)
注:RUN /ADD /COPY都会触发构建中间层镜像
b、查看 docker镜像中的 :(对磁盘有影响的 镜像)

docker images  即可!   # 列出所有image,包括  iamge
docker images -f dangling=true   # 只查看  image

c.删除所有dangling image

1、使用 docker image prune;

root@zhengzelin:~# docker image prune 
WARNING! This will remove all dangling images.    # 提示你会删除所有 dangling images !
Are you sure you want to continue? [y/N] 

部分none为容器正在运行时,强行删除的镜像,会变为none标签,此时需要删除容器后才能释放空间
[root@master ~]# docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B

[root@master ~]# docker ps -a
CONTAINER ID   IMAGE              COMMAND             CREATED          STATUS                        PORTS                     NAMES
c45ee6ab132c   c16a6ab76d40       "/assets/wrapper"   5 minutes ago    Exited (137) 21 seconds ago                             quizzical_hoover
a6a1776413b0   gitlab/gitlab-ce   "/assets/wrapper"   6 minutes ago    Exited (137) 5 minutes ago                              strange_northcutt


[root@master ~]# docker rm c45ee6ab132c
c45ee6ab132c


[root@master ~]# docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Deleted Images:
deleted: sha256:c16a6ab76d402a927ddc8214b0f0fd7b673d4d0ef74af26b76ac0bf9b76844f6
deleted: sha256:413495dba88929823c3b5228ae0efa29c287c43f0f6ad38f2e718156298515bd

Total reclaimed space: 898.3kB




2、使用 docker rmi 结合 命令:
docker rmi $(docker images -f dangling=true -q)

此时如果容器在运行中,也删除不了,除非停止容器后使用“-f”强制删除,或者删除容器后再删除 	

[root@master ~]# docker ps
CONTAINER ID   IMAGE          COMMAND             CREATED          STATUS                             PORTS                     NAMES
57de967f5123   1fd17ee09b49   "/assets/wrapper"   46 seconds ago   Up 45 seconds (health: starting)   22/tcp, 80/tcp, 443/tcp   magical_bell
[root@master ~]#
[root@master ~]#
[root@master ~]#
[root@master ~]# docker rmi -f  $(docker images -f dangling=true -q)
Error response from daemon: conflict: unable to delete 1fd17ee09b49 (cannot be forced) - image is being used by running container 57de967f5123
[root@master ~]#
[root@master ~]#
[root@master ~]# docker kill 57de967f5123
57de967f5123
[root@master ~]#
[root@master ~]#
[root@master ~]# docker rmi $(docker images -f dangling=true -q)
Error response from daemon: conflict: unable to delete 1fd17ee09b49 (must be forced) - image is being used by stopped container 57de967f5123
[root@master ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@master ~]# docker rmi -f  $(docker images -f dangling=true -q)
Deleted: sha256:1fd17ee09b49aa1cb6dc49244a2a7ec59f23bf941353633364082d8772cdea1e
 

prune命令示例;
删除未被标记和未被容器使用的镜像
docker image prune
删除所有未被现有容器使用的镜像
docker image prune -a
删除所有停止运行的容器
docker container prune
删除所有未使用的卷
docker volume prune
删除所有未使用的网络
docker network prune
一次性清理所有对象
docker system prune
注意:执行时系统会提示确认,如果不想提示,添加 -f 或者–force

你可能感兴趣的:(linux基础,docker,运维,容器)