Working with docker
Useful Docker commands for managing containers, images, volumes, and system resources.
Debug docker container
General Docker Information
docker version
: Show Docker version informationdocker info
: Display system-wide Docker informationdocker stats
: Display a live stream of container(s) resource usage statistics
Container Management
docker ps
: List running containersdocker ps -a
: List all containers (running and stopped)docker start <container>
: Start one or more stopped containersdocker stop <container>
: Stop one or more running containersdocker restart <container>
: Restart one or more containersdocker rm <container>
: Remove one or more containersdocker logs <container>
: Fetch the logs of a containerdocker exec -it <container> <command>
: Run a command in a running container
Image Management
docker images
: List imagesdocker pull <image>
: Pull an image or a repository from a registrydocker push <image>
: Push an image or a repository to a registrydocker rmi <image>
: Remove one or more imagesdocker build -t <name:tag> .
: Build an image from a Dockerfile
Volume Management
docker volume ls
: List volumesdocker volume create <name>
: Create a volumedocker volume rm <volume>
: Remove one or more volumes
Network Management
docker network ls
: List networksdocker network create <name>
: Create a networkdocker network rm <network>
: Remove one or more networks
System Management
docker system df
: Show Docker disk usagedocker system prune
: Remove unused datadocker system prune -a
: Remove all unused images not just dangling onesdocker system prune -a --volumes
: Remove all unused images and volumes
Resource Cleanup
docker container prune
: Remove all stopped containersdocker image prune
: Remove unused imagesdocker volume prune
: Remove all unused local volumesdocker network prune
: Remove all unused networks
Docker Compose
docker-compose up
: Create and start containersdocker-compose down
: Stop and remove containers, networks, images, and volumesdocker-compose ps
: List containersdocker-compose logs
: View output from containers
Advanced Commands
docker inspect <container/image>
: Return low-level information on Docker objectsdocker events
: Get real time events from the serverdocker top <container>
: Display the running processes of a container
Remember to use these commands responsibly, especially those that remove resources. Always ensure you're working in the correct environment before executing destructive commands.
Last updated