Docker Commands Cheat Sheet

I often forget the command of the docker, so I make a list as reference for myself
Here is your Docker Cheat Sheet with essential commands, organized by category. You can keep this for quick reference.

## 🐳 Docker Cheat Sheet

### General Commands
“`
docker version # Show Docker version
docker info # Show system-wide information
docker help # Show all available commands
“`
### Container Management
“`
docker ps # List running containers
docker ps -a # List all containers (including stopped)
docker ps –format “{{.ID}} {{.Names}}” # List container IDs and names
docker inspect # Get detailed information about a container
docker logs # View container logs
docker logs -f # Follow container logs
docker top # Display running processes inside a container
“`
### Container Lifecycle
“`
docker run -d # Run a container in detached mode
docker run –name # Run with a specific name
docker run -p 8080:80 # Map host port to container port
docker run -it /bin/bash # Run interactively with a shell
docker stop # Stop a running container
docker start # Start a stopped container
docker restart # Restart a container
docker rm # Remove a container
docker rm -f $(docker ps -aq) # Remove all containers (force)
“`
### Image Management
“`
docker images # List all images
docker pull # Download an image from Docker Hub
docker build -t . # Build an image from Dockerfile
docker tag : # Tag an image
docker push : # Push an image to a repository
docker rmi # Remove an image
docker rmi $(docker images -q) # Remove all images
“`
### Volumes and Storage
“`
docker volume create # Create a named volume
docker volume ls # List all volumes
docker volume inspect # Get details of a volume
docker volume rm # Remove a volume
docker run -v : # Mount a host directory
“`
### Networking
“`
docker network ls # List networks
docker network create # Create a new network
docker network inspect # Inspect a network
docker network connect # Connect a container to a network
docker network disconnect # Disconnect a container from a network
docker network rm # Remove a network
“`
### Docker Compose
“`
docker-compose up -d # Start all services in detached mode
docker-compose down # Stop and remove services
docker-compose ps # List services
docker-compose logs -f # View logs for all services
docker-compose build # Build services from Dockerfile
docker-compose restart # Restart a specific service
“`
### Docker Exec (Running Commands Inside Containers)
“`
docker exec -it bash # Open a bash shell inside a running container
docker exec -it sh # Open a shell (alternative for Alpine-based containers)
docker exec -it # Run a command inside a container
“`
### Docker System Cleanup
“`
docker system prune -a # Remove unused images, containers, and networks
docker volume prune # Remove unused volumes
docker image prune -a # Remove all dangling images
docker container prune # Remove stopped containers
“`

This cheat sheet covers the most common Docker commands you’ll need. If you need more, just let me know! 🚀

Tags:

Discover more from Juzhax Technology

Subscribe now to keep reading and get access to the full archive.

Continue reading