Remove Untagged Images From Docker

I’ve been playing around a lot with docker. It’s awesome, and it creates a whole new world of possibilities, and I’m constantly coming up with new ideas of where it could be useful.

After playing with docker for about a week on my development server, I logged in to find that my disk was completely full. I guess after dynamically spinning up dozens of containers, and building a bunch of projects with Dockerfiles I had accumulated quite a few stopped containers and untagged images. I suspect the build process to be the biggest contributor to this, as each step in your dockerfile creates a new container, which serves as the base for the next step. This is usfeul because it can cache the containers and speed up builds, but it does consume a bit of space.

I was not able to find any built-in commands for clearing stopped containers and untagged images, so I was able to put together a couple commands.

Remove all stopped containers.

docker rm $(docker ps -a -q)

This will remove all stopped containers by getting a list of all containers with docker ps -a -q and passing their ids to docker rm. This should not remove any running containers, and it will tell you it can’t remove a running image.

Remove all untagged images

In the process of running docker I had accumulated several images that are not tagged. To remove these I use this command:

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

This works by using rmi with a list of image ids. To get the image ids we call docker images then pipe it to grep "^<none>". The grep will filter it down to only lines with the value “<none>” in the repository column. Then to extract the id out of the third column we pipe it to awk "{print $3}" which will print the third column of each line passed to it.

After running these two commands I recovered 15G of space. There may be more I could do to recover more space, my docker graph directory still is over 5G, but for now this works.

from:http://jimhoskins.com/2013/07/27/remove-untagged-docker-images.html

时间: 2024-09-29 22:19:22

Remove Untagged Images From Docker的相关文章

深入浅出Docker(二):Docker命令行探秘

1. Docker命令行 Docker官方为了让用户快速了解Docker,提供了一个交互式教程,旨在帮助用户掌握Docker命令行的使用方法.但是由于Docker技术的快速发展,此交互式教程已经无法满足Docker用户的实际使用需求,所以让我们一起开始一次真正的命令行学习之旅.首先,Docker的命令清单可以通过运行docker ,或者 docker help 命令得到: $ sudo docker 在Docker容器技术不断演化的过程中,Docker的子命令已经达到34个之多,其中核心子命令(

CentOS6.6安装和使用Docker

Docker简介 docker 是一个linux 上的LXC 容器项目,是很轻量级的虚拟化技术. docker虽然基于lxc技术(cgroup.namespace等),但是思路完全和lxc不一样. lxc看起来更像是一个虚拟机,多用于操作系统级别的虚拟化,背后的哲学是 IAAS: 而docker看起来是一个程序,跑在沙箱里的程序,属于应用程序级别的虚拟化,背后的哲学是 PAAS. RHEL 6.5 开始提供docker 支持,我们使用 CentOS 6.6 x64 进行实验. 安装 yum in

docker offical docs:Working with Docker Images

Working with Docker Images ##orignal is always the best In the introduction we've discovered that Docker images are the basis of containers. In the previoussections we've used Docker images that already exist, for example the ubuntu image and thetrai

docker registry 安装步骤

实验环境 192.168.30.95  //registry server 192.168.30.96  //docker client 操作系统  centos 7.2 //-----------------------------------registry server $ docker run -d -p 5000:5000 --restart=always --name registry registry:2 $ docker pull ubuntu:16.04 $ docker ta

Docker的安装与启动

Docker安装 #yum install docker-engine (centos 6.5) 或者#curl -fsSL https://get.docker.com/ | sh 如果是出现"Warning: the "docker" command appears to already exist on this system."就意味你曾经装过docker但是失败了,这个时候需要#yum list installed | grep docker,然后把出现的

[Docker]Docker1.9后的network

.. 声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 新浪微博:@寻觅神迹 内容系本人学习.研究和总结,如有雷同,实属荣幸! Docker1.9后的network 介绍与使用 1.9之后,在Docker中network从实验特性转为正式特性发布. 从命令行可以看到新增如下命令: [[email protected] system]# docker help network Usage: docker network [OP

Docker容器简用

一.安装 ①RedHat/CentOS下的docker安装 RedHat/CentOS必须要6.6版本以上,或者7.x才能安装docker,建议在RedHat/CentOS 7上使用docker,因为RedHat/CentOS 7的内核升级到了kernel 3.10,对lxc容器支持更好. # yum -y install docker # systemctl start docker ②Ubuntu下docker安装 # sudo apt-get install docker.io # ser

docker offical docs:Working with Containers

enough ---------------------------------------------------------------------------------- Working with Containers - In the last section of the Docker User Guide we launched our first containers. We launched two containers using the docker run command

2 docker模板 镜像 容器 仓库管理

镜像管理 搜索镜像 # docker search centos [stars]:开发者的数量,应当选择开发者较多的 下载镜像 # docker pull centos 查看镜像 # docker images 复制镜像 # docker tag centos centos1[:tag] 启动镜像 docker run -t -i centos /bin/bash -t分配为终端 -i让容器标准输入打开 加上-d 即使exit退出为终端,容器也在运行,容器里的网站啊数据库都不会停止 查看镜像的运