Skip to main content
Toolsbase Logo

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

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