Download (pull) an image
docker pull <image>Downloads an image from a registry (Docker Hub by default). Pin a version tag such as nginx:1.27 rather than relying on latest.
Search common Docker tasks — run, build, debug, clean up — and get the exact command with an explanation and a warning when it deletes data.
Steps for using the Docker Command Helper.
Run nginx and publish it on port 8080
run with port
Host port: 8080 Container port: 80
Name: web Image: nginx:1.27-alpinedocker run -d -p 8080:80 --name web nginx:1.27-alpineexec, inspect and stats.The helper is a curated catalogue of everyday Docker CLI tasks grouped into images, builds, running and managing containers, debugging, volumes, networks, Compose, registries, cleanup and system commands. Search matches your words against each task's title, keywords and the command itself, so both “delete stopped containers” and “container prune” find the same card.
Placeholders such as <image> or <host-port> become input fields. Values are checked against Docker's rules — image references must be lowercase, ports must be 1–65535, environment variables must look like KEY=value — and anything containing spaces or shell characters is quoted safely before it is inserted.
Commands that remove containers, images or volumes are marked Use with care with a short explanation of what is lost. docker system prune -a --volumes and docker compose down -v in particular delete data that cannot be recovered.
Everything runs in your browser; nothing is executed. Commands target the Docker Engine CLI and Compose v2 (docker compose, not the older docker-compose).
docker <command> --help for the full reference."$(pwd)"); adjust paths and quoting for Windows PowerShell or cmd.docker run creates and starts a new container from an image. docker exec runs an extra command inside a container that is already running — for example to open a shell for debugging.
Start with docker system df to see what uses space, then docker system prune to remove stopped containers, unused networks, dangling images and build cache. Add -a to remove all unused images, and --volumes only if you are sure no volume data is needed.
Not by default — it removes containers and networks but keeps named volumes. docker compose down -v also removes the volumes, which deletes the data stored in them.
Docker repository names must be lowercase and may contain digits, dots, dashes and underscores, optionally prefixed by a registry host and followed by a :tag. MyApp:Latest is invalid; myapp:latest is fine.
58 commands
docker pull <image>Downloads an image from a registry (Docker Hub by default). Pin a version tag such as nginx:1.27 rather than relying on latest.
docker imagesdocker image ls --digestsShows images stored locally with their tags, IDs and sizes. --digests adds the content digest used for reproducible pulls.
docker tag <image> <new-image>Adds another name to the same image — for example the registry path you are about to push to. It does not copy any layers.
Careful: Removed images must be pulled or rebuilt again before they can be used.
docker image rm <image>Removes the image tag and any layers no other image uses. Fails if a container still uses it — remove the container first, or add -f.
docker history --no-trunc <image>Lists each layer with the instruction that created it and its size — handy for finding what makes an image large.
docker save -o <file> <image>Writes the image (all layers and tags) to a tar archive you can copy to an air-gapped machine.
docker load -i <file>Loads an image archive created by docker save, restoring its tags.
docker build -t <image> <context>Builds an image from the Dockerfile in the build context (usually .) and tags it. Keep a .dockerignore so the context stays small.
docker build -f <dockerfile> -t <image> <context>Uses a Dockerfile with a different name or location, e.g. Dockerfile.prod, while still sending the given context.
docker build --no-cache --pull -t <image> <context>Ignores cached layers and pulls the newest base image — useful to pick up security updates in apt-get or base layers.
docker buildx build --platform <platform> -t <image> --push <context>Builds one image for several architectures (e.g. Intel servers and ARM laptops) and pushes a multi-platform manifest. Requires a buildx builder.
docker build --build-arg <env> -t <image> <context>Sets an ARG declared in the Dockerfile, e.g. NODE_VERSION=20. Build args are visible in image history — never use them for secrets.
docker run -d --name <name> <image>Starts a new container from the image and returns immediately. --name gives it a stable name for later commands.
docker run -d -p <host-port>:<container-port> --name <name> <image>Maps a port on your machine to a port inside the container, e.g. 8080:80 serves the container's port 80 at localhost:8080.
docker run -it --rm <image> <command>Starts a throwaway container with a terminal attached (-it) and deletes it on exit (--rm). Use sh for Alpine-based images, bash otherwise.
docker run -d -e <env> --name <name> <image>docker run -d --env-file .env --name <name> <image>Sets environment variables one at a time with -e, or loads a whole .env file with --env-file.
docker run -d -v "$(pwd)"/<host-path>:<container-path> --name <name> <image>Makes a host directory visible inside the container. Changes are shared both ways — handy for live-reloading code during development.
docker run -d -v <volume>:<container-path> --name <name> <image>Stores data in a Docker-managed volume that survives container removal — the usual choice for databases.
docker run -d --restart unless-stopped --name <name> <image>Restarts the container if it crashes and when Docker starts, unless you stopped it yourself.
docker run -d --memory 512m --cpus 1.5 --name <name> <image>Caps the container at 512 MB of RAM and 1.5 CPU cores so one service cannot starve the others.
docker psdocker ps -adocker ps shows running containers; -a includes stopped ones too.
docker stop <container>Sends SIGTERM, waits 10 seconds for a graceful shutdown, then SIGKILL. The container and its data remain until removed.
docker start <container>docker restart <container>start resumes a stopped container with its original settings; restart stops and starts a running one.
Careful: Anything written inside the container (outside volumes) is lost when it is removed.
docker rm <container>docker rm -f <container>Deletes a stopped container. -f stops and removes a running one in one step.
docker rename <container> <name>Changes the container's name without restarting it.
docker cp <container>:<container-path> <host-path>docker cp <host-path> <container>:<container-path>Copies files between your machine and a container, running or stopped.
docker update --restart unless-stopped <container>Changes the restart policy (or CPU/memory limits) of an existing container without recreating it.
docker logs -f --tail <n> <container>Shows the container's output and keeps following it (-f). --tail limits how many past lines are printed first.
docker exec -it <container> <command>Runs a command in an already-running container. Use sh when the image has no bash (e.g. Alpine).
docker inspect <container>docker inspect -f '{{.NetworkSettings.IPAddress}}' <container>Prints full JSON details — mounts, environment, network settings. -f extracts a single field with a Go template.
docker statsdocker top <container>stats streams live resource usage for all running containers; top lists the processes inside one container.
docker port <container>Lists the container-to-host port mappings, e.g. 80/tcp -> 0.0.0.0:8080.
docker events --filter type=containerStreams container lifecycle events (start, die, OOM kill) — useful to see why a container keeps restarting.
docker volume create <volume>Creates a named volume. Docker also creates one automatically the first time -v name:/path is used.
docker volume lsdocker volume inspect <volume>Lists volumes, and shows where one is stored on the Docker host (Mountpoint).
docker run --rm -v <volume>:/data -v "$(pwd)":/backup alpine tar czf /backup/<volume>.tgz -C /data .Mounts the volume and your current directory into a temporary Alpine container and archives the volume's contents.
Careful: Volume data is deleted permanently — back it up first if you might need it.
docker volume rm <volume>Deletes the volume and all data in it. Fails while a container still uses it.
docker network create <network>Creates a user-defined bridge network. Containers on it can reach each other by container name.
docker run -d --network <network> --name <name> <image>Starts the container on the given network so other containers there can reach it as <name>.
docker network connect <network> <container>docker network disconnect <network> <container>Adds or removes a network from an existing container without restarting it.
docker network lsdocker network inspect <network>Shows networks, and which containers and IP addresses are attached to one.
docker compose up -dCreates and starts every service in compose.yaml (or docker-compose.yml) in the background.
docker compose up -d --buildRebuilds images for services with a build: section and recreates containers whose configuration changed.
docker compose logs -f <service>Streams logs from one service, or from every service if you leave the name out.
docker compose exec <service> <command>Opens a shell or runs a command in the running container of a service.
docker compose psShows each service's container, state, health and published ports.
Careful: down -v deletes the stack's volumes — including database data.
docker compose downdocker compose down -vStops and removes the stack's containers and networks. -v also removes its named volumes.
docker login <registry> -u <user>Prompts for a password or token and stores credentials for pushes and private pulls. Prefer --password-stdin in scripts so the token never appears in shell history.
docker tag <image> <new-image>docker push <new-image>Tags the image with the registry path, then uploads it. Only layers the registry does not already have are sent.
docker logout <registry>Removes stored credentials for the registry from this machine.
Careful: Deletes the listed resources permanently. Make sure nothing you need is stopped or unused right now.
docker container pruneDeletes every stopped container after asking for confirmation.
Careful: Deletes the listed resources permanently. Make sure nothing you need is stopped or unused right now.
docker image prunedocker image prune -aRemoves dangling (untagged) images; -a removes every image not used by a container.
Careful: --volumes deletes unused volumes and their data permanently.
docker system prunedocker system prune -a --volumesRemoves stopped containers, unused networks, dangling images and build cache. -a --volumes also removes unused images and volumes.
docker builder pruneDeletes cached build layers. Builds will be slower until the cache is rebuilt.
Careful: Stops every running container on this host, including ones other projects rely on.
docker stop $(docker ps -q)Passes every running container ID to docker stop.
docker system dfdocker system df -vSummarises space used by images, containers, volumes and build cache; -v breaks it down per item.
docker versiondocker infoversion shows client and engine versions; info shows storage driver, number of containers and daemon settings.
docker context lsdocker context use <name>Lists configured Docker endpoints and switches the CLI to another one, e.g. a remote host over SSH.