Docker
Docker Commands Cheat Sheet
A practical Docker CLI reference for containers, images, Dockerfiles, volumes, networks, Compose, registries, BuildKit, troubleshooting and production container workflows.
Docker Command Syntax
docker [command] [options] [arguments]Docker CLI commands are used to build images, create and manage containers, configure networks and volumes, run Compose applications, publish images and troubleshoot containerized workloads.
Quick Docker Command Reference
docker psdocker ps -adocker imagesdocker pull nginxdocker run -d -p 8080:80 nginxdocker logs <container>docker exec -it <container> /bin/bashdocker inspect <container>docker build -t myapp .docker network lsdocker volume lsdocker compose up -ddocker compose configdocker system dfdocker buildx lsdocker statsDocker Command Categories
Jump directly to the Docker commands you need.
1. Docker Information
7 commands
View commands →2. Docker Images
11 commands
View commands →3. Run Containers
12 commands
View commands →4. Container Management
12 commands
View commands →5. Container Logs and Inspection
10 commands
View commands →6. Execute Commands Inside Containers
6 commands
View commands →7. Copy and Transfer Files
4 commands
View commands →8. Build Docker Images
8 commands
View commands →9. Dockerfile Commands
13 commands
View commands →10. Docker Networks
8 commands
View commands →11. Docker Volumes
7 commands
View commands →12. Docker Compose
13 commands
View commands →13. Docker Registry
6 commands
View commands →14. Save, Load, Export and Import
4 commands
View commands →15. Container Resources and Health
5 commands
View commands →16. Docker System Management
9 commands
View commands →17. Docker Buildx and BuildKit
7 commands
View commands →18. Docker Contexts
5 commands
View commands →19. Docker Troubleshooting
8 commands
View commands →20. Production Docker Workflow
6 commands
View commands →1. Docker Information
7 commandsdocker --versionDisplays the installed Docker CLI version.
docker versionDisplays detailed Docker client and server version information.
docker infoDisplays detailed information about the Docker daemon, containers, images, storage and runtime.
docker helpDisplays help for Docker commands and available options.
docker system infoDisplays Docker system information using the system command group.
docker context lsLists Docker contexts available to the current CLI.
docker context showDisplays the currently selected Docker context.
2. Docker Images
11 commandsdocker imagesLists Docker images stored locally.
docker image lsLists locally available Docker images.
docker pull nginxDownloads the nginx image from a container registry.
docker pull nginx:latestDownloads a specific image tag from a container registry.
docker image inspect <image>Displays detailed metadata and configuration for an image.
docker image history <image>Shows the layers that make up a Docker image.
docker tag <image> <repository>:<tag>Creates another tag referencing an existing Docker image.
docker rmi <image>Removes a Docker image.
docker rmi -f <image>Force removes an image when normal removal is blocked.
docker image pruneRemoves dangling images that are no longer referenced.
docker image prune -aRemoves unused images that are not referenced by containers.
3. Run Containers
12 commandsdocker run nginxCreates and starts a container from the nginx image.
docker run -d nginxRuns an nginx container in detached mode.
docker run -it ubuntu bashStarts an interactive Ubuntu container with a Bash shell.
docker run --name web nginxCreates a container with a custom name.
docker run -d -p 8080:80 nginxRuns nginx and maps host port 8080 to container port 80.
docker run -d --restart unless-stopped nginxRuns a container with a restart policy that keeps it running unless explicitly stopped.
docker run --rm nginxAutomatically removes the container after it exits.
docker run -e APP_ENV=production nginxPasses an environment variable into the container.
docker run -v /host/path:/container/path nginxMounts a host directory or volume into the container.
docker run --env-file .env nginxLoads environment variables from a file.
docker run --network mynetwork nginxStarts a container attached to a specific Docker network.
docker run --memory 512m --cpus 1 nginxLimits container memory and CPU resources.
4. Container Management
12 commandsdocker psLists currently running containers.
docker ps -aLists all containers, including stopped containers.
docker ps --format '{{.Names}}'Displays container names using a custom output format.
docker start <container>Starts an existing stopped container.
docker stop <container>Gracefully stops a running container.
docker restart <container>Stops and starts a container again.
docker pause <container>Pauses all processes inside a container.
docker unpause <container>Resumes processes inside a paused container.
docker kill <container>Immediately stops a running container.
docker rm <container>Removes a stopped container.
docker rm -f <container>Force removes a running or stopped container.
docker rename <old> <new>Renames an existing container.
5. Container Logs and Inspection
10 commandsdocker logs <container>Displays logs generated by a container.
docker logs -f <container>Follows container logs in real time.
docker logs --tail 100 <container>Displays only the latest 100 lines of container logs.
docker logs --since 10m <container>Displays logs generated during the specified time period.
docker inspect <container>Displays detailed container configuration and runtime information.
docker inspect -f '{{.State.Status}}' <container>Displays the current state of a container.
docker statsContinuously monitors CPU, memory, network and block I/O usage.
docker stats <container>Monitors resource usage for a specific container.
docker top <container>Displays processes running inside a container.
docker port <container>Displays port mappings configured for a container.
6. Execute Commands Inside Containers
6 commandsdocker exec -it <container> /bin/bashOpens an interactive Bash shell inside a running container.
docker exec -it <container> /bin/shOpens a shell when Bash is not available.
docker exec <container> envDisplays environment variables inside the container.
docker exec <container> ls -laRuns a command inside the container without opening a shell.
docker exec -it <container> shStarts an interactive shell using sh.
docker exec -u root -it <container> shOpens a shell inside the container as root.
7. Copy and Transfer Files
4 commandsdocker cp <container>:/path/file.txt ./file.txtCopies a file from a container to the host.
docker cp ./file.txt <container>:/path/file.txtCopies a file from the host into a container.
docker cp ./directory <container>:/app/Copies a directory from the host into a container.
docker cp <container>:/app/logs ./logsCopies application logs from a container to the host.
8. Build Docker Images
8 commandsdocker build -t myapp .Builds a Docker image from the Dockerfile in the current directory.
docker build -t myapp:1.0 .Builds an image with a specific repository name and tag.
docker build -f Dockerfile.prod -t myapp:prod .Builds an image using a specific Dockerfile.
docker build --no-cache -t myapp .Builds an image without using cached layers.
docker build --pull -t myapp .Attempts to pull newer versions of base images before building.
docker build --build-arg APP_ENV=production -t myapp .Passes a build argument to the Docker build process.
docker build --target production -t myapp:prod .Builds a specific target from a multi-stage Dockerfile.
docker build --progress=plain -t myapp .Displays detailed build output useful for troubleshooting.
9. Dockerfile Commands
13 commandsFROM node:22Defines the base image for a Docker image.
WORKDIR /appSets the working directory inside the image.
COPY . .Copies files from the build context into the image.
ADD archive.tar.gz /app/Adds files or supported archives to the image.
RUN npm installExecutes a command while building the image.
ENV NODE_ENV=productionDefines an environment variable in the image.
ARG APP_VERSION=1.0Defines a build-time argument.
EXPOSE 3000Documents the port the application is intended to use.
CMD ["npm", "start"]Defines the default command executed when a container starts.
ENTRYPOINT ["node"]Defines the main executable for the container.
USER nodeSets the default user used when running the container.
HEALTHCHECK CMD curl --fail http://localhost:3000/ || exit 1Defines a container health check.
VOLUME ["/data"]Declares a mount point intended for persistent data.
10. Docker Networks
8 commandsdocker network lsLists Docker networks.
docker network inspect <network>Displays detailed information about a Docker network.
docker network create mynetworkCreates a user-defined Docker network.
docker network create --driver bridge mynetworkCreates a bridge network explicitly.
docker network connect mynetwork <container>Connects an existing container to a network.
docker network disconnect mynetwork <container>Disconnects a container from a network.
docker network rm <network>Removes a Docker network.
docker network pruneRemoves unused Docker networks.
11. Docker Volumes
7 commandsdocker volume lsLists Docker volumes.
docker volume create myvolumeCreates a named Docker volume.
docker volume inspect myvolumeDisplays detailed information about a Docker volume.
docker run -v myvolume:/data nginxMounts a named volume at /data inside the container.
docker run --mount source=myvolume,target=/data nginxMounts a volume using the explicit --mount syntax.
docker volume rm myvolumeRemoves a Docker volume.
docker volume pruneRemoves unused Docker volumes.
12. Docker Compose
13 commandsdocker compose upCreates and starts services defined in compose.yaml.
docker compose up -dStarts Compose services in detached mode.
docker compose downStops and removes Compose services, networks and containers created by the project.
docker compose psLists containers managed by the Compose project.
docker compose logsDisplays logs from Compose services.
docker compose logs -fFollows Compose service logs in real time.
docker compose buildBuilds images defined in the Compose configuration.
docker compose pullPulls images required by the Compose project.
docker compose exec <service> shExecutes an interactive shell inside a Compose service container.
docker compose restart <service>Restarts a specific Compose service.
docker compose stop <service>Stops a specific Compose service.
docker compose configValidates and renders the final Compose configuration.
docker compose up -d --buildRebuilds required images and starts Compose services.
13. Docker Registry
6 commandsdocker loginAuthenticates the Docker CLI with a container registry.
docker logoutLogs out of a container registry.
docker tag myapp username/myapp:latestTags an image for a registry repository.
docker push username/myapp:latestPushes a tagged image to a container registry.
docker pull username/myapp:latestDownloads an image from a container registry.
docker image inspect username/myapp:latestInspects metadata for a registry image after pulling it.
14. Save, Load, Export and Import
4 commandsdocker save -o myapp.tar myapp:latestExports a Docker image and its layers to a tar archive.
docker load -i myapp.tarLoads Docker images from a tar archive.
docker export -o container.tar <container>Exports a container filesystem to a tar archive.
docker import container.tar myimage:latestCreates a Docker image from a filesystem tar archive.
15. Container Resources and Health
5 commandsdocker stats <container>Monitors live CPU, memory, network and block I/O usage.
docker inspect <container>Inspects resource limits, mounts, networking and runtime configuration.
docker update --memory 512m <container>Updates the memory limit of an existing container.
docker update --cpus 1 <container>Updates the CPU limit of an existing container.
docker inspect --format '{{.State.Health.Status}}' <container>Displays the health status of a container with a health check.
16. Docker System Management
9 commandsdocker system dfShows Docker disk usage by images, containers, volumes and build cache.
docker system pruneRemoves unused Docker resources.
docker system prune -aRemoves unused resources including unused images.
docker container pruneRemoves stopped containers.
docker image pruneRemoves dangling images.
docker network pruneRemoves unused Docker networks.
docker volume pruneRemoves unused Docker volumes.
docker builder pruneRemoves unused build cache.
docker builder prune -aRemoves all unused build cache.
17. Docker Buildx and BuildKit
7 commandsdocker buildx versionDisplays the installed Docker Buildx version.
docker buildx lsLists available Buildx builders.
docker buildx create --name mybuilder --useCreates a Buildx builder and switches the CLI to it.
docker buildx inspectDisplays information about the active Buildx builder.
docker buildx build -t myapp:latest .Builds an image using Buildx.
docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest --push .Builds and pushes a multi-platform image.
docker buildx pruneRemoves unused Buildx build cache.
18. Docker Contexts
5 commandsdocker context lsLists available Docker contexts.
docker context showShows the active Docker context.
docker context inspect <context>Displays configuration details for a Docker context.
docker context use <context>Switches the Docker CLI to another context.
docker context create <context> --docker host=ssh://user@hostCreates a Docker context that connects to a remote Docker host over SSH.
19. Docker Troubleshooting
8 commandsdocker ps -aCheck whether a container exited or failed to start.
docker logs <container>Check application or startup errors in container logs.
docker inspect <container>Inspect container configuration, networking, mounts and runtime state.
docker statsCheck whether containers are consuming excessive CPU or memory.
docker network inspect <network>Investigate container network configuration and connected containers.
docker system dfCheck whether Docker is consuming excessive disk space.
docker eventsStreams Docker daemon events useful for troubleshooting container lifecycle problems.
docker inspect --format '{{.State.ExitCode}}' <container>Checks the exit code of a container.
20. Production Docker Workflow
6 commandsdocker build -t myapp:1.0 .Builds a versioned application image.
docker image inspect myapp:1.0Inspects the built image before deployment.
docker run -d --name myapp -p 8080:3000 --restart unless-stopped myapp:1.0Runs a production-style container with port mapping and restart policy.
docker logs --tail 100 myappChecks the latest application logs after deployment.
docker stats myappMonitors the running application container.
docker exec -it myapp shOpens a shell for application troubleshooting.
Docker Troubleshooting Workflow
# Check Docker installation docker --version # Check Docker daemon docker info # Check running containers docker ps # Check all containers docker ps -a # Inspect container details docker inspect <container> # Check container logs docker logs <container> # Follow logs docker logs -f <container> # Check processes docker top <container> # Check resource usage docker stats # Check port mappings docker port <container> # Check networks docker network ls # Inspect a network docker network inspect <network> # Check Docker disk usage docker system df # Check build cache docker builder prune # Check image layers docker image history <image> # Check image metadata docker image inspect <image> # Check Docker events docker events
Start withdocker ps -ato determine the container state, then checkdocker logsanddocker inspect. If the application is running but unreachable, verify port mappings and Docker networks. For performance problems, inspect CPU and memory usage withdocker stats.
DevOpsToolbox Tip
When a container is not working, start withdocker ps -a, then checkdocker logsanddocker inspect. For production deployments, use versioned image tags, health checks, restart policies, resource limits and a controlled cleanup strategy.