Basic Commands
-
Check Docker version
docker --version
-
List all Docker commands
docker
-
List Docker CLI help
docker --help
Working with Images
-
List all images
docker images
-
Pull an image from a registry
docker pull <image-name>
-
Build an image from a Dockerfile
docker build -t <image-name> <path>
-
Remove an image
docker rmi <image-id>
Working with Containers
-
List running containers
docker ps
-
List all containers (including stopped ones)
docker ps -a
-
Start a container
docker start <container-id>
-
Stop a container
docker stop <container-id>
-
Restart a container
docker restart <container-id>
-
Remove a container
docker rm <container-id>
-
Run a container from an image
docker run -it <image-name>
-
Run a container in the background
docker run -d <image-name>
Inspecting Containers
-
Get logs of a container
docker logs <container-id>
-
Show detailed information about a container
docker inspect <container-id>
-
Show real-time statistics of containers
docker stats
-
Access a running container
docker exec -it <container-id> /bin/bash
Networking
-
List networks
docker network ls
-
Create a network
docker network create <network-name>
-
Connect a container to a network
docker network connect <network-name> <container-id>
-
Disconnect a container from a network
docker network disconnect <network-name> <container-id>
Volumes
-
List volumes
docker volume ls
-
Create a volume
docker volume create <volume-name>
-
Remove a volume
docker volume rm <volume-name>
Docker Compose Commands
-
Check Docker Compose version
docker-compose --version
-
List all Docker Compose commands
docker-compose
Working with Compose Files
-
Start services defined in a docker-compose file
docker-compose up
-
Start services in the background
docker-compose up -d
-
Stop services
docker-compose down
-
Build or rebuild services
docker-compose build
-
Stop services without removing them
docker-compose stop
-
Start stopped services
docker-compose start
-
Restart services
docker-compose restart
Inspecting and Managing Services
-
List running services
docker-compose ps
-
View logs of services
docker-compose logs
-
View logs of a specific service
docker-compose logs <service-name>
-
Run a one-off command on a service
docker-compose run <service-name> <command>
-
Scale services
docker-compose scale <service-name>=<number>
-
Remove stopped service containers
docker-compose rm
-
Pull images for services defined in a Compose file
docker-compose pull