Reference · Reference
Docker Commands Reference
A categorized reference for 74 essential Docker CLI commands (Docker 29.x). 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 run
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 ps
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 stop
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 start
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 rm
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 exec
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 logs
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 inspect
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 cp
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 stats
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 build
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 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 rmi
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 tag
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 pull
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 push
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 save
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 load
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 up
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 down
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 build
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 ps
Key Points
- -a: Show stopped containers as well
- --format: Customize output format
Examples
docker compose psList the status of all servicesdocker compose logs
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 exec
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 run
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 config
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 create
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 ls
Key Points
- --filter: Filter by condition
- -q: Only display network IDs
Examples
docker network lsList all networksdocker network inspect
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 connect
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 disconnect
Key Points
- -f, --force: Force the container to disconnect from a network
Examples
docker network disconnect multi-host-network container1Disconnect a container from a networkdocker network rm
Key Points
- Cannot remove a network with active containers
- Can remove multiple networks at once
Examples
docker network rm mynetRemove a networkdocker network prune
Key Points
- -f: Skip confirmation prompt
- --filter: Filter by condition (e.g. until=timestamp)
Examples
docker network prune -fRemove all unused networks without confirmationdocker volume create
Key Points
- -d: Specify the driver
- --label: Set metadata labels
Examples
docker volume create mydataCreate a volumedocker volume ls
Key Points
- --filter: Filter by condition
- -q: Only display volume names
Examples
docker volume lsList all volumesdocker volume inspect
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 rm
Key Points
- -f: Force removal
- Cannot remove a volume that is in use
Examples
docker volume rm mydataRemove a volumedocker volume prune
Key Points
- -f: Skip confirmation prompt
- --filter: Filter by condition
Examples
docker volume prune -fRemove all unused volumes without confirmationdocker login
Key Points
- -u: Specify the username
- -p: Specify the password (not recommended; use --password-stdin instead)
- --password -: Pass a hyphen as the value to read the password from stdin
- --password-stdin: Read the password from stdin
Examples
docker loginLog in to Docker Hubdocker login registry.example.comLog in to a private registrydocker logout
Key Points
- Removes stored credentials
- You can specify a registry URL
Examples
docker logoutLog out from Docker Hubdocker search
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 inspect
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 df
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 prune
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 info
Key Points
- Check storage driver, network settings, and more
- -f: Specify output format using a Go template
Examples
docker infoDisplay detailed Docker environment informationdocker version
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 ls
Key Points
- --format: Customize output format
- Used to manage remote Docker environments
Examples
docker context lsList all registered contextsdocker buildx build
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 locallydocker restart
Key Points
- -t: Seconds to wait before forcing stop (default 10)
- Runs stop followed by start internally
Examples
docker restart myappRestart a containerdocker restart -t 30 myappWait 30 seconds before restartingdocker kill
Key Points
- -s: Signal to send (default KILL)
- Terminates immediately, unlike stop which waits for the timeout
Examples
docker kill myappForce-stop a container immediatelydocker kill -s SIGTERM myappSend SIGTERM for graceful shutdowndocker pause
Key Points
- Uses the cgroups freezer to pause processes
- Resume with docker unpause
Examples
docker pause myappPause a running containerdocker unpause
Key Points
- Restores execution after docker pause
Examples
docker unpause myappResume a paused containerdocker rename
Key Points
- Works on both running and stopped containers
- The new name must not conflict with existing containers
Examples
docker rename old-name new-nameRename a container from old-name to new-namedocker port
Key Points
- Shows the host-side mapping of ports published with -p
- Specify a port to view a single mapping
Examples
docker port myappShow all port mappingsdocker port myapp 80Show the host port mapped to container port 80docker wait
Key Points
- Returns the exit status of the container
- Useful in CI or batch jobs to wait for completion
Examples
docker wait myappWait for the container to exit and print the codedocker top
Key Points
- Accepts ps options as additional arguments
- Inspect the in-container process tree from the host
Examples
docker top myappList processes in the containerdocker top myapp auxDisplay in ps aux formatdocker container prune
Key Points
- -f: Skip the confirmation prompt
- --filter: Narrow with conditions like until=24h
Examples
docker container prune -fDelete every stopped containerdocker container prune -f --filter until=24hDelete containers stopped more than 24 hours agodocker image prune
Key Points
- -a: Remove all images not referenced by any container
- -f: Skip the confirmation prompt
- --filter: Narrow with conditions like until=72h
Examples
docker image prune -fRemove only dangling imagesdocker image prune -a -fRemove all unreferenced imagesdocker history
Key Points
- --no-trunc: Show full commands without truncation
- -q: Show only image IDs
- --format: Use a Go template to customize output
Examples
docker history nginx:latestInspect the layers of the Nginx imagedocker history --no-trunc myapp:latestView the full build commands per layerdocker import
Key Points
- -c: Apply Dockerfile-style instructions (CMD, ENV, etc.)
- -m: Set a commit message
- --platform: Specify the platform
Examples
docker import backup.tar myimage:importedCreate an image from a tarballcat rootfs.tar.gz | docker import - mybase:latestImport from standard inputdocker export
Key Points
- -o: Write to a file instead of stdout
- Image history and metadata are not included (unlike docker save)
Examples
docker export -o backup.tar myappWrite a container to backup.tardocker export myapp | gzip > backup.tar.gzExport and compress the resultdocker compose pull
Key Points
- --ignore-pull-failures: Continue on partial failures
- --include-deps: Also pull images for dependency services
- -q: Suppress progress output
Examples
docker compose pullUpdate images for every servicedocker compose pull web dbPull only the specified servicesdocker compose restart
Key Points
- -t: Seconds to wait before forcing stop
- Restarts every service when no service name is provided
Examples
docker compose restartRestart all servicesdocker compose restart webRestart only the web servicedocker events
Key Points
- --since / --until: Filter by time range
- --filter: Filter by type, event, etc. (e.g., type=container)
- --format: Use a Go template to customize output
Examples
docker eventsWatch every event in real timedocker events --filter type=container --filter event=dieWatch only container exit eventsdocker context create
Key Points
- --docker: Connection details (e.g., host=ssh://user@host)
- --description: Human-readable description
- Switch between local and remote Docker engines
Examples
docker context create remote --docker host=ssh://user@example.comCreate a context that connects to a remote Docker over SSHdocker context use
Key Points
- Use docker context use default to return to local
- Can also be set via the DOCKER_CONTEXT environment variable
Examples
docker context use remoteSwitch to the remote contextdocker context use defaultReturn to the local Docker enginedocker buildx create
Key Points
- --name: Builder name
- --use: Activate the builder upon creation
- --driver: Choose the driver (e.g., docker-container)
Examples
docker buildx create --name multiarch --useCreate and immediately activate the multiarch builderdocker buildx ls
Key Points
- The active builder is marked with *
- Shows supported platforms and status
Examples
docker buildx lsList all buildersdocker scout cves
Key Points
- --only-severity: Filter by severity (critical, high, etc.)
- --format: Output format such as sarif
- Available with Docker Desktop or the Docker CLI extension
Examples
docker scout cves nginx:latestList all vulnerabilities in the Nginx imagedocker scout cves --only-severity critical,high myapp:latestShow only Critical and High vulnerabilitiesdocker attach
Key Points
- --detach-keys: Override the key sequence for detaching a container
- --no-stdin: Do not attach STDIN
- --sig-proxy: Proxy all received signals to the process (default true)
- If the container was run with -i and -t, detach with CTRL-p CTRL-q and leave it running
- Returns the exit code of the process you attached to
Examples
docker attach myappAttach to the standard streams of a running containerdocker attach --no-stdin myappAttach for output only, without STDINdocker commit
Key Points
- -a, --author: Author of the image
- -c, --change: Apply a Dockerfile instruction to the created image
- -m, --message: Commit message
- --no-pause: Disable pausing the container during commit
Examples
docker commit myapp myimage:v1Create a new image from the container's current statedocker commit -m fix-config -a dev-team myapp myimage:v2Commit with a message and an authordocker commit --change 'ENV DEBUG=true' myapp myimage:debugApply a Dockerfile instruction while committingdocker create
Key Points
- --name: Assign a name to the container
- -p: Publish a container's port to the host (host:container)
- -v: Bind mount a volume
- -e: Set environment variables
- --network: Connect the container to a network
- Similar to docker run -d except the container is never started; start it later with docker start
Examples
docker create --name myapp nginxCreate a container without starting itdocker create -i -t --name mycontainer alpineCreate an interactive container to start later with docker startdocker create -p 8080:80 --name web nginxCreate a container with a port mappingdocker diff
Key Points
- A: A file or directory was added
- C: A file or directory was changed
- D: A file or directory was deleted
- Takes no flags — pass only the container name or ID
Examples
docker diff myappList files changed since the container started from its imagedocker update
Key Points
- --cpus: Number of CPUs
- -c, --cpu-shares: CPU shares (relative weight)
- -m, --memory: Memory limit
- --memory-swap: Swap limit equal to memory plus swap (-1 for unlimited)
- --pids-limit: Tune container pids limit (-1 for unlimited)
- --restart: Restart policy to apply when a container exits
- Not supported for Windows containers; containers started with --rm cannot have their restart policy updated
Examples
docker update --cpu-shares 512 -m 300M myappUpdate CPU shares and the memory limit togetherdocker update --restart=on-failure:3 myappChange the restart policy to on-failure with up to 3 retriesAbout Docker Commands Reference
The Docker Commands Reference organizes 74 essential Docker CLI commands (Docker 29.x) by category. Quickly look up commands for container lifecycle management (run, start, stop, restart, kill, pause), image build and distribution (build, buildx, push, pull, history), multi-container orchestration with Docker Compose (compose up/down/pull/restart), network and volume configuration, context switching, and Docker Scout vulnerability scanning — all with search and copy functionality.
Key Features
- 74 Docker commands organized into 7 categories (Docker 29.x)
- Real-time search across command names, descriptions, options, and examples
- Covers latest subcommands: buildx, scout, context
- One-click copy with 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.