Docker Commands Reference
A categorized reference for essential Docker CLI commands. Search and copy commands for container management, image builds, Compose, networking, volumes, registry, and system operations.
Last updated:
How to Use
Expand how to useCollapse how to use
- 1
Filter by Category
Click a category button to narrow down commands by container, image, Compose, and more.
- 2
Search Commands
Type a keyword in the search box to search across command names, descriptions, options, and examples in real time.
- 3
Copy a Command
Click the copy button on a card to copy the command to your clipboard.
docker runCreate and run a new container
Key Points
- -d: Run in background (detached mode)
- -p: Port mapping (host:container)
- --name: Assign a name to the container
- -v: Mount a volume
- --rm: Automatically remove the container on exit
- -e: Set environment variables
- --network: Specify the network to connect to
Examples
docker run -d -p 8080:80 nginxStart Nginx in the background, accessible on port 8080docker run --rm -it ubuntu bashStart an interactive Ubuntu container that removes itself on exitdocker run -d --name myapp -e NODE_ENV=production -p 3000:3000 node:20Start a named Node.js app in production modedocker psList running containers
Key Points
- -a: Show all containers including stopped ones
- -q: Only display container IDs
- --filter: Filter by condition
- --format: Customize output format
Examples
docker psList running containersdocker ps -aShow all containers including stopped onesdocker ps -q --filter status=exitedGet IDs of stopped containers onlydocker stopStop a running container
Key Points
- -t: Seconds to wait before killing the container. Default 10s
- Can stop multiple containers at once
Examples
docker stop myappStop a container by namedocker stop $(docker ps -q)Stop all running containersdocker startStart a stopped container
Key Points
- -a: Attach mode (connect to stdout)
- -i: Interactive mode
Examples
docker start myappStart a stopped containerdocker start -ai myappStart a container in interactive modedocker rmRemove a container
Key Points
- -f: Force remove even if running
- -v: Also remove anonymous volumes associated with the container
Examples
docker rm myappRemove a stopped containerdocker rm -f $(docker ps -aq)Force remove all containersdocker execExecute a command inside a running container
Key Points
- -it: Open an interactive terminal session
- -d: Run in background
- -e: Set environment variables
- -w: Set the working directory
Examples
docker exec -it myapp bashStart a bash shell inside the containerdocker exec myapp cat /etc/hostsDisplay a file inside the containerdocker logsFetch the logs of a container
Key Points
- -f: Follow log output in real time
- --tail: Show only the last N lines
- -t: Show timestamps
- --since: Show logs since a specific time
Examples
docker logs -f myappFollow log output in real timedocker logs --tail 100 myappShow the last 100 lines of logsdocker logs --since 1h myappShow logs from the past hourdocker inspectReturn detailed information on a container or image in JSON format
Key Points
- -f: Specify output format using a Go template
- --type: Specify the type of object (container, image, network, etc.)
Examples
docker inspect myappShow detailed information about a containerdocker inspect -f '{{.NetworkSettings.IPAddress}}' myappGet only the container's IP addressdocker cpCopy files between a container and the host
Key Points
- Supports both container→host and host→container directions
- -a: Archive mode (preserve owner and permissions)
Examples
docker cp myapp:/app/logs ./logsCopy logs from the container to the hostdocker cp ./config.json myapp:/app/Copy a config file from the host to the containerdocker statsDisplay a live stream of container resource usage
Key Points
- --no-stream: Print stats only once and exit
- --format: Customize output format
Examples
docker statsShow resource usage for all containersdocker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}'Print CPU and memory usage once in table formatdocker buildBuild an image from a Dockerfile
Key Points
- -t: Name and optionally a tag for the image
- -f: Specify the path to the Dockerfile
- --no-cache: Build without using cache
- --build-arg: Set build-time variables
- --target: Set the target build stage in a multi-stage build
Examples
docker build -t myapp:latest .Build an image from the current directorydocker build -t myapp:v1 -f Dockerfile.prod .Build using a production Dockerfiledocker build --no-cache -t myapp:latest .Clean build without cachedocker imagesList local images
Key Points
- -a: Show all images including intermediate ones
- -q: Only show image IDs
- --filter: Filter by condition
Examples
docker imagesList local imagesdocker images --filter dangling=trueShow untagged (dangling) imagesdocker rmiRemove one or more images
Key Points
- -f: Force removal
- Can remove multiple images at once
Examples
docker rmi myapp:latestRemove a specific imagedocker rmi $(docker images -q --filter dangling=true)Remove all dangling images at oncedocker tagCreate a tag that refers to a source image
Key Points
- Add a new name/tag to an existing image
- Prepend a registry URL before pushing
Examples
docker tag myapp:latest myapp:v1.0Add a version tagdocker tag myapp:latest registry.example.com/myapp:latestTag an image for a private registrydocker pullPull an image from a registry
Key Points
- --platform: Specify the platform (e.g., linux/amd64)
- -a: Pull all tagged images
Examples
docker pull nginx:latestPull the latest Nginx imagedocker pull --platform linux/arm64 node:20Pull Node.js 20 for ARM64docker pushUpload an image to a registry
Key Points
- Requires docker login beforehand
- Include the registry URL in the tag before pushing
Examples
docker push myuser/myapp:latestPush an image to Docker Hubdocker push registry.example.com/myapp:v1.0Push to a private registrydocker saveSave an image to a tar archive
Key Points
- -o: Specify the output file
- Used to transfer images to offline environments
Examples
docker save -o myapp.tar myapp:latestSave an image to a tar filedocker loadLoad an image from a tar archive
Key Points
- -i: Specify the input file
- Restores an image saved with docker save
Examples
docker load -i myapp.tarLoad an image from a tar filedocker compose upCreate and start services defined in Compose
Key Points
- -d: Start in background (detached mode)
- --build: Build images before starting
- --force-recreate: Recreate containers even if unchanged
- --scale: Scale a service to the specified number of instances
Examples
docker compose up -dStart all services in the backgrounddocker compose up -d --buildBuild and then start in the backgrounddocker compose up -d --scale web=3Start the web service with 3 instancesdocker compose downStop and remove services started by Compose
Key Points
- -v: Also remove volumes
- --rmi all: Also remove images
- --remove-orphans: Remove containers not defined in Compose
Examples
docker compose downStop services and remove containersdocker compose down -vRemove everything including volumesdocker compose buildBuild or rebuild services defined in Compose
Key Points
- --no-cache: Build without using cache
- --pull: Always pull a newer version of the base image
Examples
docker compose buildBuild images for all servicesdocker compose build --no-cache webBuild the web service without cachedocker compose psList containers managed by Compose
Key Points
- -a: Show stopped containers as well
- --format: Customize output format
Examples
docker compose psList the status of all servicesdocker compose logsView log output from Compose services
Key Points
- -f: Follow log output in real time
- --tail: Show only the last N lines
- Specify a service name to filter logs
Examples
docker compose logs -f webFollow log output from the web servicedocker compose logs --tail 50Show the last 50 lines from all servicesdocker compose execExecute a command in a running Compose service container
Key Points
- -T: Disable pseudo-TTY allocation (for CI/CD)
- -e: Set environment variables
Examples
docker compose exec web bashStart bash in the web service containerdocker compose exec db psql -U postgresConnect to PostgreSQL in the db servicedocker compose runRun a one-off command on a Compose service
Key Points
- --rm: Remove the container after it exits
- --no-deps: Don't start linked services
- -e: Set environment variables
Examples
docker compose run --rm web npm testRun tests in the web service and remove the container afterwarddocker compose run --rm db pg_dump -U postgres mydb > backup.sqlCreate a database backupdocker compose configValidate and display the Compose configuration
Key Points
- --services: Only display service names
- --volumes: Only display volume names
- -q: Only validate the configuration, show nothing if valid
Examples
docker compose configDisplay the merged configurationdocker compose config --servicesList all defined service namesdocker network createCreate a Docker network
Key Points
- -d: Specify the driver (bridge, overlay, etc.)
- --subnet: Specify the subnet
- --gateway: Specify the gateway
Examples
docker network create mynetCreate a bridge networkdocker network create --subnet 172.20.0.0/16 mynetCreate a network with a specific subnetdocker network lsList Docker networks
Key Points
- --filter: Filter by condition
- -q: Only display network IDs
Examples
docker network lsList all networksdocker network inspectDisplay detailed information on a network
Key Points
- -f: Specify output format using a Go template
- Also shows the list of connected containers
Examples
docker network inspect mynetShow detailed information about a networkdocker network connectConnect a container to a network
Key Points
- --ip: Assign a static IP address
- --alias: Specify an alias within the network
Examples
docker network connect mynet myappConnect a container to a networkdocker network rmRemove one or more Docker networks
Key Points
- Cannot remove a network with active containers
- Can remove multiple networks at once
Examples
docker network rm mynetRemove a networkdocker volume createCreate a Docker volume
Key Points
- -d: Specify the driver
- --label: Set metadata labels
Examples
docker volume create mydataCreate a volumedocker volume lsList Docker volumes
Key Points
- --filter: Filter by condition
- -q: Only display volume names
Examples
docker volume lsList all volumesdocker volume inspectDisplay detailed information on a volume
Key Points
- -f: Specify output format using a Go template
- Check mount point and driver information
Examples
docker volume inspect mydataShow detailed information about a volumedocker volume rmRemove one or more Docker volumes
Key Points
- -f: Force removal
- Cannot remove a volume that is in use
Examples
docker volume rm mydataRemove a volumedocker volume pruneRemove all unused volumes
Key Points
- -f: Skip confirmation prompt
- --filter: Filter by condition
Examples
docker volume prune -fRemove all unused volumes without confirmationdocker loginLog in to a registry
Key Points
- -u: Specify the username
- -p: Specify the password (not recommended; use --password-stdin instead)
- --password-stdin: Read the password from stdin
Examples
docker loginLog in to Docker Hubdocker login registry.example.comLog in to a private registrydocker logoutLog out from a registry
Key Points
- Removes stored credentials
- You can specify a registry URL
Examples
docker logoutLog out from Docker Hubdocker searchSearch Docker Hub for images
Key Points
- --filter: Filter by condition (stars, is-official, etc.)
- --limit: Maximum number of results to display
- --format: Customize output format
Examples
docker search nginxSearch for Nginx imagesdocker search --filter is-official=true nodeSearch for official Node.js imagesdocker manifest inspectDisplay an image's manifest information
Key Points
- Check supported architectures of multi-platform images
- --verbose: Display verbose output
Examples
docker manifest inspect nginx:latestDisplay the manifest for the Nginx imagedocker system dfShow Docker disk usage
Key Points
- -v: Show detailed breakdown
- Check usage for images, containers, volumes, and build cache
Examples
docker system dfShow a summary of disk usagedocker system df -vShow detailed disk usagedocker system pruneRemove unused Docker resources
Key Points
- -a: Also remove all unused images
- --volumes: Also remove volumes
- -f: Skip confirmation prompt
- --filter: Filter by condition
Examples
docker system prune -fRemove unused resources without confirmationdocker system prune -a --volumes -fRemove all unused resources including images and volumesdocker infoDisplay system-wide Docker information
Key Points
- Check storage driver, network settings, and more
- -f: Specify output format using a Go template
Examples
docker infoDisplay detailed Docker environment informationdocker versionShow the Docker version information
Key Points
- Displays client and server version details
- -f: Specify output format using a Go template
Examples
docker versionDisplay version informationdocker version --format '{{.Server.Version}}'Show only the server versiondocker context lsList Docker contexts
Key Points
- --format: Customize output format
- Used to manage remote Docker environments
Examples
docker context lsList all registered contextsdocker buildx buildBuild multi-platform images using BuildKit
Key Points
- --platform: Specify the target platform(s)
- --push: Push the image to a registry after building
- --load: Load the built image into the local image store
- --cache-from / --cache-to: Specify external cache sources and destinations
Examples
docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest --push .Build for both AMD64 and ARM64 and pushdocker buildx build --load -t myapp:latest .Build with BuildKit and load locallyAbout Docker Commands Reference
The Docker Commands Reference is a tool that organizes essential Docker CLI commands by category. Quickly look up commands for container lifecycle management, image builds and distribution, multi-container management with Docker Compose, and network and volume configuration — all with search and copy functionality.
Key Features
- 46 Docker commands organized into 7 categories
- Real-time search across command names, descriptions, options, and examples
- One-click command copy
- Practical usage examples for each command
When It's Useful
- Looking up the correct syntax for docker run, exec, or logs during local development
- Referencing Docker Compose commands when setting up a multi-service dev environment
- Checking network and volume management commands for a containerized application
- Finding the right docker system prune or image cleanup commands to free up disk space
- Using as a cheat sheet when writing or debugging a Dockerfile or CI/CD pipeline
- Onboarding new developers to Docker and containerization workflows
Frequently Asked Questions
What is the difference between docker compose and docker-compose?
docker compose (with a space) is Compose V2, integrated into the Docker CLI v2. docker-compose (with a hyphen) is the older standalone binary (V1). Compose V2 is now the recommended approach.
How do I remove unused images and containers in bulk?
Run docker system prune -a --volumes -f to remove stopped containers, unused networks, untagged images, and unused volumes all at once. Be cautious with -f (skip confirmation) in production environments.
When should I use docker run vs docker compose up?
Use docker run for single containers. For multiple containers working together (app + DB + cache, etc.), use docker compose up and manage configuration in a docker-compose.yml file.
How do I build multi-platform images?
Use docker buildx build --platform linux/amd64,linux/arm64. With BuildKit enabled, it's common to combine this with the --push option to push directly to a registry.
How do I view container logs in real time?
Use docker logs -f <container-name> to follow logs in real time. For Docker Compose, use docker compose logs -f <service-name>. You can limit the number of lines with the --tail option.
