My Docker cheatsheet
- Remove all Docker images
- Remove stopped containers, unused networks, dangling images, dangling build caches, unused volumes
- Add your user to the Docker group
- Get container shell
- Find out about your Docker setup
- Check size of images, containers and volumes
- Stop all containers
- Check Docker logs
- Limit the size of Docker logs
- Aliasing docker-compose to docker compose
- Useful links
Stuff I find myself Googling for the nth time
Remove all Docker images
docker rmi $(docker images -a -q)Remove stopped containers, unused networks, dangling images, dangling build caches, unused volumes
docker system prune --volumes
# Note also -a [all] and -f [force] options
## To remove "dangling" (unused) Docker volumes
docker volume rm $(docker volume ls -qf dangling=true)
# To remove networks
docker network pruneAdd your user to the Docker group
To run Docker commands without sudo
sudo groupadd docker # may be required - may need a restart
sudo usermod -aG docker paul # then log out and back inGet container shell
docker exec -it <container-id> /bin/bashIf you get a weird error with this, then it may be that Bash is not available in the container and you should use sh instead.
Find out about your Docker setup
docker infoCheck size of images, containers and volumes
docker system dfStop all containers
docker stop $(docker ps -q)Check Docker logs
docker logs <container-id>Limit the size of Docker logs
Logs are unlimited by default - can limit to 50MB
In /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "50m",
"max-file": "3"
}
}then
sudo systemctl restart dockerOther configuration options here
Aliasing docker-compose to docker compose
in e.g. .bashrc
alias docker-compose="docker compose --compatibility $@"