Skip to main content

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 use
  1. 1

    Filter by Category

    Click a category button to narrow down commands by container, image, Compose, and more.

  2. 2

    Search Commands

    Type a keyword in the search box to search across command names, descriptions, options, and examples in real time.

  3. 3

    Copy a Command

    Click the copy button on a card to copy the command to your clipboard.

docker run

Create 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 nginx
Start Nginx in the background, accessible on port 8080
docker run --rm -it ubuntu bash
Start an interactive Ubuntu container that removes itself on exit
docker run -d --name myapp -e NODE_ENV=production -p 3000:3000 node:20
Start a named Node.js app in production mode

docker ps

List 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 ps
List running containers
docker ps -a
Show all containers including stopped ones
docker ps -q --filter status=exited
Get IDs of stopped containers only

docker stop

Stop a running container

Key Points

  • -t: Seconds to wait before killing the container. Default 10s
  • Can stop multiple containers at once

Examples

docker stop myapp
Stop a container by name
docker stop $(docker ps -q)
Stop all running containers

docker start

Start a stopped container

Key Points

  • -a: Attach mode (connect to stdout)
  • -i: Interactive mode

Examples

docker start myapp
Start a stopped container
docker start -ai myapp
Start a container in interactive mode

docker rm

Remove a container

Key Points

  • -f: Force remove even if running
  • -v: Also remove anonymous volumes associated with the container

Examples

docker rm myapp
Remove a stopped container
docker rm -f $(docker ps -aq)
Force remove all containers

docker exec

Execute 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 bash
Start a bash shell inside the container
docker exec myapp cat /etc/hosts
Display a file inside the container

docker logs

Fetch 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 myapp
Follow log output in real time
docker logs --tail 100 myapp
Show the last 100 lines of logs
docker logs --since 1h myapp
Show logs from the past hour

docker inspect

Return 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 myapp
Show detailed information about a container
docker inspect -f '{{.NetworkSettings.IPAddress}}' myapp
Get only the container's IP address

docker cp

Copy 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 ./logs
Copy logs from the container to the host
docker cp ./config.json myapp:/app/
Copy a config file from the host to the container

docker stats

Display a live stream of container resource usage

Key Points

  • --no-stream: Print stats only once and exit
  • --format: Customize output format

Examples

docker stats
Show resource usage for all containers
docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}'
Print CPU and memory usage once in table format

docker build

Build 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 directory
docker build -t myapp:v1 -f Dockerfile.prod .
Build using a production Dockerfile
docker build --no-cache -t myapp:latest .
Clean build without cache

docker images

List local images

Key Points

  • -a: Show all images including intermediate ones
  • -q: Only show image IDs
  • --filter: Filter by condition

Examples

docker images
List local images
docker images --filter dangling=true
Show untagged (dangling) images

docker rmi

Remove one or more images

Key Points

  • -f: Force removal
  • Can remove multiple images at once

Examples

docker rmi myapp:latest
Remove a specific image
docker rmi $(docker images -q --filter dangling=true)
Remove all dangling images at once

docker tag

Create 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.0
Add a version tag
docker tag myapp:latest registry.example.com/myapp:latest
Tag an image for a private registry

docker pull

Pull an image from a registry

Key Points

  • --platform: Specify the platform (e.g., linux/amd64)
  • -a: Pull all tagged images

Examples

docker pull nginx:latest
Pull the latest Nginx image
docker pull --platform linux/arm64 node:20
Pull Node.js 20 for ARM64

docker push

Upload 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:latest
Push an image to Docker Hub
docker push registry.example.com/myapp:v1.0
Push to a private registry

docker save

Save 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:latest
Save an image to a tar file

docker load

Load 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.tar
Load an image from a tar file

docker compose up

Create 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 -d
Start all services in the background
docker compose up -d --build
Build and then start in the background
docker compose up -d --scale web=3
Start the web service with 3 instances

docker compose down

Stop 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 down
Stop services and remove containers
docker compose down -v
Remove everything including volumes

docker compose build

Build 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 build
Build images for all services
docker compose build --no-cache web
Build the web service without cache

docker compose ps

List containers managed by Compose

Key Points

  • -a: Show stopped containers as well
  • --format: Customize output format

Examples

docker compose ps
List the status of all services

docker compose logs

View 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 web
Follow log output from the web service
docker compose logs --tail 50
Show the last 50 lines from all services

docker compose exec

Execute 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 bash
Start bash in the web service container
docker compose exec db psql -U postgres
Connect to PostgreSQL in the db service

docker compose run

Run 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 test
Run tests in the web service and remove the container afterward
docker compose run --rm db pg_dump -U postgres mydb > backup.sql
Create a database backup

docker compose config

Validate 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 config
Display the merged configuration
docker compose config --services
List all defined service names

docker network create

Create a Docker network

Key Points

  • -d: Specify the driver (bridge, overlay, etc.)
  • --subnet: Specify the subnet
  • --gateway: Specify the gateway

Examples

docker network create mynet
Create a bridge network
docker network create --subnet 172.20.0.0/16 mynet
Create a network with a specific subnet

docker network ls

List Docker networks

Key Points

  • --filter: Filter by condition
  • -q: Only display network IDs

Examples

docker network ls
List all networks

docker network inspect

Display 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 mynet
Show detailed information about a network

docker network connect

Connect 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 myapp
Connect a container to a network

docker network disconnect

Disconnect a container from a network

Key Points

  • -f, --force: Force the container to disconnect from a network

Examples

docker network disconnect multi-host-network container1
Disconnect a container from a network

docker network rm

Remove one or more Docker networks

Key Points

  • Cannot remove a network with active containers
  • Can remove multiple networks at once

Examples

docker network rm mynet
Remove a network

docker network prune

Remove all unused networks

Key Points

  • -f: Skip confirmation prompt
  • --filter: Filter by condition (e.g. until=timestamp)

Examples

docker network prune -f
Remove all unused networks without confirmation

docker volume create

Create a Docker volume

Key Points

  • -d: Specify the driver
  • --label: Set metadata labels

Examples

docker volume create mydata
Create a volume

docker volume ls

List Docker volumes

Key Points

  • --filter: Filter by condition
  • -q: Only display volume names

Examples

docker volume ls
List all volumes

docker volume inspect

Display 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 mydata
Show detailed information about a volume

docker volume rm

Remove one or more Docker volumes

Key Points

  • -f: Force removal
  • Cannot remove a volume that is in use

Examples

docker volume rm mydata
Remove a volume

docker volume prune

Remove all unused volumes

Key Points

  • -f: Skip confirmation prompt
  • --filter: Filter by condition

Examples

docker volume prune -f
Remove all unused volumes without confirmation

docker login

Log in to a registry

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 login
Log in to Docker Hub
docker login registry.example.com
Log in to a private registry

docker logout

Log out from a registry

Key Points

  • Removes stored credentials
  • You can specify a registry URL

Examples

docker logout
Log out from Docker Hub

docker search

Search 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 nginx
Search for Nginx images
docker search --filter is-official=true node
Search for official Node.js images

docker manifest inspect

Display an image's manifest information

Key Points

  • Check supported architectures of multi-platform images
  • --verbose: Display verbose output

Examples

docker manifest inspect nginx:latest
Display the manifest for the Nginx image

docker system df

Show Docker disk usage

Key Points

  • -v: Show detailed breakdown
  • Check usage for images, containers, volumes, and build cache

Examples

docker system df
Show a summary of disk usage
docker system df -v
Show detailed disk usage

docker system prune

Remove 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 -f
Remove unused resources without confirmation
docker system prune -a --volumes -f
Remove all unused resources including images and volumes

docker info

Display system-wide Docker information

Key Points

  • Check storage driver, network settings, and more
  • -f: Specify output format using a Go template

Examples

docker info
Display detailed Docker environment information

docker version

Show the Docker version information

Key Points

  • Displays client and server version details
  • -f: Specify output format using a Go template

Examples

docker version
Display version information
docker version --format '{{.Server.Version}}'
Show only the server version

docker context ls

List Docker contexts

Key Points

  • --format: Customize output format
  • Used to manage remote Docker environments

Examples

docker context ls
List all registered contexts

docker buildx build

Build 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 push
docker buildx build --load -t myapp:latest .
Build with BuildKit and load locally

docker restart

Restart one or more containers

Key Points

  • -t: Seconds to wait before forcing stop (default 10)
  • Runs stop followed by start internally

Examples

docker restart myapp
Restart a container
docker restart -t 30 myapp
Wait 30 seconds before restarting

docker kill

Send a signal to a running container

Key Points

  • -s: Signal to send (default KILL)
  • Terminates immediately, unlike stop which waits for the timeout

Examples

docker kill myapp
Force-stop a container immediately
docker kill -s SIGTERM myapp
Send SIGTERM for graceful shutdown

docker pause

Suspend all processes inside a running container

Key Points

  • Uses the cgroups freezer to pause processes
  • Resume with docker unpause

Examples

docker pause myapp
Pause a running container

docker unpause

Resume processes inside a paused container

Key Points

  • Restores execution after docker pause

Examples

docker unpause myapp
Resume a paused container

docker rename

Rename a container

Key Points

  • Works on both running and stopped containers
  • The new name must not conflict with existing containers

Examples

docker rename old-name new-name
Rename a container from old-name to new-name

docker port

List public ports for a container

Key Points

  • Shows the host-side mapping of ports published with -p
  • Specify a port to view a single mapping

Examples

docker port myapp
Show all port mappings
docker port myapp 80
Show the host port mapped to container port 80

docker wait

Block until a container exits and print its exit code

Key Points

  • Returns the exit status of the container
  • Useful in CI or batch jobs to wait for completion

Examples

docker wait myapp
Wait for the container to exit and print the code

docker top

Display the running processes inside a container

Key Points

  • Accepts ps options as additional arguments
  • Inspect the in-container process tree from the host

Examples

docker top myapp
List processes in the container
docker top myapp aux
Display in ps aux format

docker container prune

Remove all stopped containers

Key Points

  • -f: Skip the confirmation prompt
  • --filter: Narrow with conditions like until=24h

Examples

docker container prune -f
Delete every stopped container
docker container prune -f --filter until=24h
Delete containers stopped more than 24 hours ago

docker image prune

Remove unused images

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 -f
Remove only dangling images
docker image prune -a -f
Remove all unreferenced images

docker history

Show the layer history of an image

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:latest
Inspect the layers of the Nginx image
docker history --no-trunc myapp:latest
View the full build commands per layer

docker import

Import an image from a tarball or URL

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:imported
Create an image from a tarball
cat rootfs.tar.gz | docker import - mybase:latest
Import from standard input

docker export

Export a container's filesystem as a tar archive

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 myapp
Write a container to backup.tar
docker export myapp | gzip > backup.tar.gz
Export and compress the result

docker compose pull

Pull images for all services defined in docker-compose.yml

Key Points

  • --ignore-pull-failures: Continue on partial failures
  • --include-deps: Also pull images for dependency services
  • -q: Suppress progress output

Examples

docker compose pull
Update images for every service
docker compose pull web db
Pull only the specified services

docker compose restart

Restart Compose services

Key Points

  • -t: Seconds to wait before forcing stop
  • Restarts every service when no service name is provided

Examples

docker compose restart
Restart all services
docker compose restart web
Restart only the web service

docker events

Stream real-time events from the Docker daemon

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 events
Watch every event in real time
docker events --filter type=container --filter event=die
Watch only container exit events

docker context create

Create a new Docker context

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.com
Create a context that connects to a remote Docker over SSH

docker context use

Switch the active Docker context

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 remote
Switch to the remote context
docker context use default
Return to the local Docker engine

docker buildx create

Create a Buildx builder for multi-platform builds

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 --use
Create and immediately activate the multiarch builder

docker buildx ls

List Buildx builders

Key Points

  • The active builder is marked with *
  • Shows supported platforms and status

Examples

docker buildx ls
List all builders

docker scout cves

Scan an image for vulnerabilities with Docker Scout

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:latest
List all vulnerabilities in the Nginx image
docker scout cves --only-severity critical,high myapp:latest
Show only Critical and High vulnerabilities

docker attach

Attach local standard input, output, and error streams to a running container

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 myapp
Attach to the standard streams of a running container
docker attach --no-stdin myapp
Attach for output only, without STDIN

docker commit

Create a new image from a container's changes

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:v1
Create a new image from the container's current state
docker commit -m fix-config -a dev-team myapp myimage:v2
Commit with a message and an author
docker commit --change 'ENV DEBUG=true' myapp myimage:debug
Apply a Dockerfile instruction while committing

docker create

Create a new container without starting it

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 nginx
Create a container without starting it
docker create -i -t --name mycontainer alpine
Create an interactive container to start later with docker start
docker create -p 8080:80 --name web nginx
Create a container with a port mapping

docker diff

Inspect changes to files or directories on a container's filesystem

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 myapp
List files changed since the container started from its image

docker update

Update configuration of one or more containers

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 myapp
Update CPU shares and the memory limit together
docker update --restart=on-failure:3 myapp
Change the restart policy to on-failure with up to 3 retries

About 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.