Skip to content

Docker

140 commands

The Docker CLI: build, run and inspect containers and images, and audit their configuration, mounts, capabilities and networks.

  • containers
  • images

Install Docker

sudo apt install docker.io

Basic Setup and Verification5

docker --version

Outputs the installed Docker CLI version to verify installation

docker version

Displays detailed version information for both Docker Client and Server

docker info

Shows system-wide information including kernel version, storage driver, and container counts

docker help

Lists all available commands and global options for the Docker CLI

docker login

Authenticates the Docker client against a container registry

Link

Image Management12

docker search

Searches Docker Hub for public images with an optional limit

Link
docker pull

Downloads a specific image tag from a registry to the local cache

Link
docker images

Lists all top-level images currently stored locally

docker image ls -a

Lists all local images including intermediate image layers

docker tag

Creates a new tag for an existing local image

Link
docker push

Uploads a locally tagged image to a remote registry

Link
docker rmi

Removes one or more images from the local storage

Link
docker rmi -f

Forces the removal of an image even if containers are using it

Link
docker image prune

Removes all unused images, not just dangling ones

Link
docker history

Shows the history of layers and commands used to build an image

Link
docker save

Exports an image to a tar archive for offline transfer

Link
docker load

Loads an image from a tar archive into the local docker engine

Link

Container Lifecycle14

docker create

Creates a new container layer but does not start it

Link
docker start

Starts one or more stopped containers

Link
docker run -it

Creates and starts a container in interactive mode with a TTY

Link
docker run -d

Runs a container in detached mode in the background

Link
docker run --rm

Runs a container that automatically removes itself upon exit

Link
docker ps

Lists currently running containers

Link
docker ps -a

Lists all containers including stopped ones

Link
docker stop

Gracefully stops a running container by sending SIGTERM

Link
docker kill

Forcibly stops a container by sending SIGKILL

Link
docker restart

Stops and then immediately starts a container

Link
docker pause

Pauses all processes within one or more containers

Link
docker unpause

Resumes all processes within one or more paused containers

Link
docker rm

Removes a stopped container from the system

Link
docker rm -f

Forcibly removes a running container

Link

Container Interaction6

docker exec

Runs a new command inside a running container interactively

Link
docker attach

Attaches local standard input, output, and error to a running container

Link
docker logs

Fetches the logs of a container

Link
docker logs -f

Streams the logs of a container in real-time

Link
docker cp container to host

Copies a file from a container to the host filesystem

Link
docker cp host to container

Copies a file from the host filesystem into a container

Link

Container Inspection5

docker inspect

Returns low-level information on a container or object in JSON format

Link
docker stats

Displays a live stream of container resource usage statistics

Link
docker top

Display the running processes of a container

Link
docker diff

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

Link
docker port

Lists port mappings for the container

Link

Networking9

docker network ls

Lists all networks created by Docker

Link
docker network create

Creates a new bridge network for containers to communicate

Link
docker network inspect

Displays detailed information about a network

Link
docker network connect

Connects a running container to a network

Link
docker network disconnect

Disconnects a container from a network

Link
docker network rm

Removes one or more networks

Link
docker run -p

Maps host port 8080 to container port 80

Link
docker run --network host

Runs container using the host's networking stack directly

Link
docker run --dns

Sets custom DNS servers for the container

Link

Storage and Volumes7

docker volume ls

Lists all Docker volumes

Link
docker volume create

Creates a new named volume for persistent storage

Link
docker volume inspect

Displays detailed information about a volume

Link
docker run -v volume

Mounts a named volume to a path inside the container

Link
docker run -v bind

Binds a host directory to a path inside the container

Link
docker volume rm

Removes a Docker volume

Link
docker volume prune

Removes all unused local volumes

Link

Building Images5

docker build

Builds an image from a Dockerfile in the current directory

Link
docker build file

Builds an image using a specific Dockerfile filename

Link
docker build no-cache

Builds an image without using the build cache

Link
docker build args

Passes build-time variables to the Dockerfile

Link
docker build target

Builds only up to a specific stage in a multi-stage Dockerfile

Link

System Maintenance3

docker system df

Show docker disk usage

Link
docker system prune

Remove unused data including stopped containers and dangling images

Link
docker container prune

Removes all stopped containers

Link

Security and Isolation6

docker run --user

Runs the container as a specific non-root user ID and group ID

Link
docker run --read-only

Mounts the container's root filesystem as read-only

Link
docker run --cap-drop

Drops all Linux capabilities from the container for hardening

Link
docker run --cap-add

Adds specific Linux capabilities to the container

Link
docker run --privileged

Runs container with full host root capabilities (Use with extreme caution)

Link
docker run --security-opt

Prevents the container processes from gaining new privileges

Link

Resource Limits3

docker run --memory

Limits the memory usage of the container

Link
docker run --cpus

Limits the container to use 50% of a CPU core

Link
docker run --pids-limit

Limits the number of processes a container can start

Link

Advanced Networking4

docker network create overlay

Creates a multi-host overlay network (requires Swarm mode)

Link
docker run --mac-address

Sets a static MAC address for the container network interface

Link
docker run --add-host

Adds a custom entry to the container's /etc/hosts file

Link
docker network create -d overlay

Generates a distributed overlay network allowing swarm containers deployed on completely different physical servers to communicate securely natively.

Link

Logging and Debugging4

docker logs --tail

Shows only the last 10 lines of container logs

Link
docker logs --timestamps

Adds timestamps to the log output

Link
docker events

Streams real-time events from the Docker daemon

Link
docker events filter

Filters system events to show only container termination events

Link

Advanced Storage3

docker volume create options

Creates a volume with specific driver options

Link
docker run --mount

Uses the explicit mount syntax for clearer bind mounting

Link
docker run --tmpfs

Mounts a temporary filesystem in memory that is removed when container stops

Link

Docker Contexts3

docker context ls

Lists available Docker contexts for managing multiple endpoints

Link
docker context create

Creates a context to manage a remote Docker daemon via SSH

Link
docker context use

Switches the Docker CLI to operate against a specific context

Link

Docker Compose Integration3

docker compose up

Builds and starts containers defined in docker-compose.yml

Link
docker compose down

Stops and removes containers and networks defined in docker-compose.yml

Link
docker compose logs

Views output from containers defined in the compose file

Link

Advanced Management4

docker export

Exports a container's filesystem as a tar archive (without history)

Link
docker import

Imports the contents from a tarball to create a filesystem image

Link
docker commit

Creates a new image from a container's changes (Not recommended for production)

Link
docker wait

Blocks until a container stops, then prints its exit code

Link

Registry & Trust3

docker logout

Logs out from a Docker registry

Link
docker trust inspect

Returns trust and signing data for an image

Link
docker manifest inspect

Inspects the image manifest to see supported architectures and layers

Link

Blue Team & Forensics4

docker inspect format

Extracts specific data like IP address using Go templates

Link
docker inspect mounts

Extracts detailed mounting information for security audit

Link
docker diff check

Checks for unauthorized file modifications inside a compromised container

Link
docker history no-trunc

Views full command history to find secrets or bad commands in image build

Link

DevSecOps Workflows2

docker scan

Scans the image for vulnerabilities (requires Docker Scan plugin)

Link
docker sbom

Generates a Software Bill of Materials for the image (requires plugin)

Link

Container Hardening3

docker run --ulimit

Sets specific ulimits like open file descriptors for the container

Link
docker run --device

Adds a specific host device to the container

Link
docker run --cgroup-parent

Specifies the parent cgroup for the container to inherit limits

Link

Swarm (Basic)3

docker swarm init

Initializes a swarm on the current node

Link
docker service create

Creates a replicated service in a Docker Swarm

Link
docker service ls

Lists services running in the swarm

Link

Advanced Runtime9

docker run --runtime

Specifies a custom OCI runtime for the container

Link
docker run --init

Runs an init process inside the container to forward signals and reap zombies

Link
docker run --entrypoint

Overwrites the default ENTRYPOINT of the image

Link
docker run --workdir

Sets the working directory inside the container

Link
docker run --env

Sets environment variables inside the container

Link
docker run --env-file

Reads environment variables from a file

Link
docker run --health-cmd

Defines a command to run to check container health

Link
docker run --health-interval

Sets the time between health checks

Link
docker run --cidfile

Writes the container ID to a file upon startup

Link

Advanced Automation2

docker kill signal

Sends a specific custom signal to the container process

Link
docker system dial-stdio

Proxies the standard input/output to the API connection (Advanced internal use)

Link

Incident Response2

docker container inspect state

Quickly retrieves the exit code of a crashed container

Link
docker cp forensics

Extracts application logs for forensic analysis without entering the container

Link

System Cleanup2

docker builder prune

Cleans up the build cache to free up disk space

Link
docker system prune volumes

Deep cleans the system including unused volumes

Link

Docker Compose4

docker compose up -d

Starts all services defined in a docker-compose.yml in detached background mode.

Link
docker compose down -v

Stops all compose services and forcefully removes the named volumes attached to them, performing a complete clean state wipe.

Link
docker compose ps

Lists the current status, ports, and health of containers strictly managed by the local docker-compose configuration.

Link
docker compose logs -f <service>

Tails and follows the logs explicitly for one isolated microservice defined inside the compose stack.

Link

Docker Swarm5

docker swarm init

Initializes the machine as a Docker Swarm Master Manager node, generating the join tokens required for worker nodes.

Link
docker swarm join-token worker

Reveals the strict command and cryptographic token required for a remote machine to securely join this specific swarm.

Link
docker node ls

Lists all active nodes participating in the swarm matrix, their reachability status, and whether they are managers or workers.

Link
docker service create

Deploys a horizontally scaled service directly into the swarm, automatically load balancing requests across 3 isolated replicas.

Link
docker service logs <serviceName>

Aggregates and tails the logs from all scattered swarm replicas belonging to this service into a single unified output stream.

Link

Buildx (Advanced BuildKit)2

docker buildx create --use

Spins up and activates a new sophisticated BuildKit environment unlocking multi-architecture compiling capabilities.

Link
docker buildx build --platform

Cross-compiles the current Dockerfile for multiple disparate architectures (Apple Silicon / Intel) simultaneously and pushes the manifest to the registry.

Link

Advanced Data Volumes1

docker volume prune -a

Dangerously destroys every single data volume on the system that is not currently actively mounted by a running container.

Link

Security & Namespaces2

docker top <container_id>

Maps internal container PIDs directly to their corresponding Host Operating System PIDs bridging the namespace isolated visibility.

Link
docker cp <container_id>:<path> <local_path>

Forcefully circumvents mounting architectures to directly extract or inject raw files out of a running container's sandbox.

Link