Remove Untagged Images From Docker
2017-10-26 14:08
369 查看
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.
http://jimhoskins.com/2013/07/27/remove-untagged-docker-images.html
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 -qand 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 imagesthen 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.
http://jimhoskins.com/2013/07/27/remove-untagged-docker-images.html
相关文章推荐
- Remove Untagged Images From Docker
- Docker-删除untagged docker images
- how to remove untagged / none images
- docker rm -f Error response from daemon: Driver overlay failed to remove root filesystem
- [Docker] Download and Remove Docker Images
- Remove Duplicates from Sorted Array
- Remove Nth Node From End of List - LeetCode
- lintcode-easy-Remove Nth Node from End of List
- LeetCode Remove Duplicates from Sorted Array
- Leetcode-Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- [LeetCode]26. Remove Duplicates from Sorted Array
- leetcode[82] Remove Duplicates from Sorted List II
- Remove “Shared Folder Synchronization” from Right Click Context Menu
- leetcode — remove-duplicates-from-sorted-list-ii
- 26. Remove Duplicates from Sorted Array i && ii
- 解决cocos2dx调用removeFromParent后报错问题
- LeetCode-19. Remove Nth Node From End of List
- leetcode:Remove Duplicates from Sorted List 【Java】
- LeetCode 19. Remove Nth Node From End of List