Snippets
Created by
Giuliano Ribeiro
last modified
Docker - How to cleanup (unused) resources
Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...
delete volumes
// see: https://github.com/chadoe/docker-cleanup-volumes
$ docker volume rm $(docker volume ls -qf dangling=true)
$ docker volume ls -qf dangling=true | xargs -r docker volume rm
delete networks
$ docker network ls
$ docker network ls | grep "bridge"
$ docker network rm $(docker network ls | grep "bridge" | awk '/ / { print $1 }')
remove docker images
// see: http://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images
$ docker images
$ docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
$ docker images | grep "none"
$ docker rmi $(docker images | grep "none" | awk '/ / { print $3 }')
remove docker containers
// see: http://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images
$ docker ps
$ docker ps -a
$ docker rm $(docker ps -qa --no-trunc --filter "status=exited")
Resize disk space for docker vm
$ docker-machine create --driver virtualbox --virtualbox-disk-size "40000" default
In Centos:
ENV http_proxy=192.168.0.193:3128
ENV https_proxy=192.168.0.193:3128
In Ubuntu:
ENV http_proxy 'http://192.168.0.193:3128'
ENV https_proxy 'http://192.168.0.193:3128'
If you need set proxy in coreos, for example to pull the image
cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://192.168.0.193:3128"
Build docker image from dockerfile
docker build -t user/container .
Run Container in background and bind all ports
docker run -d -P -t user/container
Run container in same network as host binding port to 8080
docker run -p 8080:8080 -d --net host user/container
Run bash on the container
docker run -it user/container bash
Copy files insde the container to HOST
docker cp mycontainer:/foo.txt foo.txt
Get information(IP, PORTs, etc...) for a specific container
docker inspect user/container
Stop all Containers
docker stop $(docker ps -a -q)
Delete all Untaged Container Images
docker rmi -f $(docker images | grep "<none>" | awk "{print \$3}")
Delete OLD Containers
docker rm `docker ps -aq`
Container Stats
docker stats $CONTAINER_ID $OR_CONTAINER_NAME $ANOTHER_CONAINER_NAME
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.