Skip to content

Instantly share code, notes, and snippets.

@1activegeek
Created March 26, 2020 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1activegeek/cd6f5b9597bd969ef72452dde5a4fdf0 to your computer and use it in GitHub Desktop.
Save 1activegeek/cd6f5b9597bd969ef72452dde5a4fdf0 to your computer and use it in GitHub Desktop.
Useful snippets for docker cleanup tasks

Docker Cleanup

Host cleanup - cleanup old kernels for ubuntu and other various apt related updates
apt-get autoclean
apt-get autoremove

List out the volumes that are no longer necessary or used

docker volume ls -qf dangling=true

Remove the volumes listed above

docker volume rm $(docker volume ls -qf dangling=true)

list leftover images not being used by Containers

docker images -q -f dangling=true

Remove leftover images not being used by Containers

docker rmi $(docker images -q -f dangling=true)

Stop all containers

docker stop $(docker ps -a -q)

Remove all containers

docker rm $(docker ps -a -q)

Copy contents from inside a container (https://docs.docker.com/engine/reference/commandline/cp/)

docker cp <container-name>:</container/directory> </local/path>

For further cleanup automation scripts

https://lebkowski.name/docker-volumes/

Output running nginx config in LS.io LE Container:

docker exec -it <container_name> bash
mkdir /run/nginx
cp /run/nginx.pd /run/nginx
nginx -T -c /config/nginx/nginx.conf (or substitute your mapped location to your nginx.conf)

Browse container filesystem from host:

Find PID of container
docker inspect --format {{.State.Pid}} $YOUR_CONTAINER
Browse filesystem
/proc/$(docker inspect --format {{.State.Pid}} $YOUR_CONTAINER)/root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment