System Information #
Command | Description |
---|---|
docker version |
Show Docker version information |
docker system info |
Display system-wide information |
docker system df |
Show Docker disk usage |
docker system prune |
Remove unused containers, networks, and dangling images |
docker system prune -a |
Remove all unused containers, networks, and ALL images |
Basic Commands #
Command | Description |
---|---|
docker run [OPTIONS] IMAGE [COMMAND] |
Run a container |
docker ps |
List running containers |
docker ps -a |
List all containers (including stopped) |
docker ps --no-trunc |
Show complete command output (not truncated) |
docker stop CONTAINER |
Stop a container |
docker rm CONTAINER |
Remove a container |
docker pull IMAGE[:TAG] |
Pull an image from registry |
docker images |
List images |
docker build -t IMAGE_NAME:TAG . |
Build an image from Dockerfile |
Container Lifecycle #
Command | Description |
---|---|
docker start CONTAINER |
Start a stopped container |
docker restart CONTAINER |
Restart a container |
docker pause CONTAINER |
Pause a container |
docker unpause CONTAINER |
Unpause a container |
docker logs CONTAINER |
Get container logs |
docker logs -f CONTAINER |
Follow container logs |
docker stats |
Display live container resource usage |
docker inspect CONTAINER |
Show detailed container information |
docker exec -it CONTAINER COMMAND |
Execute command in running container |
docker exec -it CONTAINER /bin/sh |
Get a shell inside the container |
docker top CONTAINER |
Display running processes in a container |
docker container prune |
Remove all stopped containers |
docker rename OLD_NAME NEW_NAME |
Rename a container |
docker kill CONTAINER |
Send SIGKILL to a container |
Docker Compose #
Command | Description |
---|---|
docker compose up |
Start services defined in compose.yaml |
docker compose up -d |
Start services in detached mode |
docker compose down |
Stop services |
docker compose down -v |
Stop services and remove volumes |
docker compose logs |
View logs |
docker compose logs -f |
Follow logs |
docker compose ps |
List containers |
docker compose exec SERVICE COMMAND |
Execute command in a service |
docker compose build |
Build or rebuild services |
docker compose pull |
Pull service images |
docker compose restart |
Restart services |
docker compose rm |
Remove stopped service containers |
docker compose up -d --scale SERVICE=NUM |
Scale a service |
docker compose config |
Validate and view the compose file |
Images and Volumes #
Command | Description |
---|---|
docker rmi IMAGE |
Remove an image |
docker image prune |
Remove dangling images |
docker image prune -a |
Remove all unused images |
docker image history IMAGE |
Show image history |
docker image ls |
List images |
docker save IMAGE > file.tar |
Save image to a tar archive |
docker load < file.tar |
Load image from a tar archive |
docker tag SOURCE_IMAGE TARGET_IMAGE |
Create a tag for an image |
docker commit CONTAINER IMAGE_NAME |
Create image from a container |
docker volume create VOLUME_NAME |
Create a volume |
docker volume ls |
List volumes |
docker volume inspect VOLUME_NAME |
Display detailed volume information |
docker volume rm VOLUME_NAME |
Remove a volume |
docker volume prune |
Remove unused volumes |
Network #
Command | Description |
---|---|
docker network create NETWORK_NAME |
Create a network |
docker network ls |
List networks |
docker network inspect NETWORK |
Display detailed network information |
docker network connect NETWORK CONTAINER |
Connect container to network |
docker network disconnect NETWORK CONTAINER |
Disconnect container from network |
docker network prune |
Remove all unused networks |
Docker Hub #
Command | Description |
---|---|
docker login |
Log in to Docker Hub |
docker logout |
Log out from Docker Hub |
docker search TERM |
Search Docker Hub for images |
docker push IMAGE_NAME |
Push image to Docker Hub |
Common Options #
Option | Description |
---|---|
-d |
Run container in background (detached mode) |
-p HOST_PORT:CONTAINER_PORT |
Map a port |
-v HOST_PATH:CONTAINER_PATH |
Mount a volume |
--name CONTAINER_NAME |
Assign a name to container |
-e KEY=VALUE |
Set environment variables |
--network NETWORK |
Connect to a network |
--restart=always |
Always restart container |
-i |
Keep STDIN open even if not attached |
-t |
Allocate a pseudo-TTY |
-it |
Interactive with TTY (combines -i and -t) |
--rm |
Remove container when it exits |
--memory="512m" |
Memory limit |
--cpus="0.5" |
CPU limit |
--user USER |
Username or UID |
--workdir DIR |
Working directory in container |
--entrypoint CMD |
Override the default entrypoint |
--health-cmd CMD |
Health check command |
-s, --signal |
Signal to send to the container when stopping |
--stop-timeout |
Seconds to wait for stop before killing |