Date: 2023-03-13
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 prune
Add 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 in
Get container shell
docker exec -it <container-id> /bin/bash
If 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 info
Check size of images, containers and volumes
docker system df
Stop 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 docker
Other configuration options here
Aliasing docker-compose to docker compose
in e.g. .bashrc
alias docker-compose="docker compose --compatibility $@"