D

Docker

Docker CLI commands for images, containers, networks, volumes and Compose.

Updated 2026-09-03

On this page

Images

docker images

Lists locally stored images.

docker pull IMAGE:TAG

Downloads an image from a registry without running it.

docker rmi IMAGE_ID
destructive

Deletes a local image. Fails if a container still references it — remove the container first.

docker tag SOURCE_IMAGE TARGET_IMAGE

Creates an additional tag for an image — the usual step before pushing to a registry under a versioned or environment-specific name.

docker push TARGET_IMAGE

Uploads a tagged image to its registry.

Build

docker build -t app .

Builds an image from the Dockerfile in the current directory, tagged app:latest.

docker build -t app:1.2.0 -f Dockerfile.prod .

Builds with an explicit tag and a non-default Dockerfile path.

docker build --no-cache -t app .

Builds without using any cached layers — for confirming a build is reproducible, or ruling out a stale cache as the cause of a bug.

Containers

docker ps

Lists running containers.

docker ps -a

Lists all containers, including stopped ones.

docker run -d -p 8080:80 app

Runs a container in the background, mapping host port 8080 to container port 80.

docker run -it --rm app /bin/sh

Runs a container interactively and removes it automatically on exit — the standard pattern for a throwaway debugging shell.

docker stop CONTAINER_ID

Sends SIGTERM and waits for graceful shutdown before killing the container.

docker rm CONTAINER_ID
destructive

Removes a stopped container and its writable layer permanently. Add -f to stop and remove in one step.

docker restart CONTAINER_ID

Stops and starts a container in place, keeping its configuration and name.

Exec & Logs

docker exec -it CONTAINER_ID bash

Opens an interactive shell inside a running container.

docker logs CONTAINER_ID

Prints a container's stdout/stderr output.

docker logs -f CONTAINER_ID

Streams logs live.

docker inspect CONTAINER_ID

Dumps full container configuration as JSON — mounts, network settings, env vars, resource limits.

docker stats

Shows live CPU, memory, network and I/O usage per running container.

Networks

docker network ls

Lists Docker networks.

docker network create my-network

Creates a user-defined bridge network — containers on it can resolve each other by container name, unlike the default bridge.

docker network inspect my-network

Shows which containers are attached to a network and their IPs.

Volumes

docker volume ls

Lists named volumes.

docker volume create my-data

Creates a named volume, managed by Docker and independent of any single container's lifecycle.

docker run -v my-data:/var/lib/data app

Mounts a named volume into a container at the given path.

Registry

docker login

Authenticates against a registry (Docker Hub by default, or pass a registry hostname).

docker logout

Removes cached credentials for a registry.

Cleanup

docker system prune

Removes stopped containers, unused networks, and dangling (untagged) images. Prompts for confirmation.

docker system prune -a --volumes
destructive

Also removes every image not used by a running container, and every unused volume — including named volumes holding data nothing is currently using. Confirm nothing important is stored only in an idle volume first.

docker container prune

Removes all stopped containers only.

Docker Compose

docker compose up -d

Starts every service defined in compose.yaml in the background.

docker compose down

Stops and removes containers and networks created by up. Add -v to also remove named volumes.

docker compose logs -f SERVICE_NAME

Streams logs for one service in the compose project.

docker compose ps

Lists the containers for the current compose project and their status.

docker compose exec SERVICE_NAME sh

Opens a shell in a running service container, addressed by its compose service name rather than a container ID.

docker compose build

Rebuilds images for services with a build: block, without starting them.

See the Docker Troubleshooting tab for containers that exit immediately, won't build, or can't reach the network.

Official documentation