Docker CLI Basics
Everyday Docker Engine CLI commands for containers. Results appear in the same fence: same-line # comments when short, multiline # blocks below the sample when not. Fences are bash, dockerfile, or yaml as appropriate.
Search across all documentation pages
Everyday Docker Engine CLI commands for containers. Results appear in the same fence: same-line # comments when short, multiline # blocks below the sample when not. Fences are bash, dockerfile, or yaml as appropriate.
Create and start a container from an image.
docker run --rm -d --name web -p 8080:80 nginx:alpine
# container id printed; maps host 8080 -> container 80List running containers (add -a for all).
docker ps --format '{{.Names}} {{.Status}}'
# web Up 10 secondsStream or fetch container logs.
docker logs --tail 100 -f web
# last 100 lines then followRun a command in a running container.
docker exec -it web sh -c 'echo hi'
# hiGraceful stop (SIGTERM then SIGKILL after timeout).
docker stop web
# webRemove stopped containers.
docker rm web
# webJSON metadata for a container or image.
docker inspect -f '{{.State.Status}}' web
# runningPass environment variables.
docker run --rm -e GREETING=hello alpine:3.20 printenv GREETING
# helloBind mount a host path.
docker run --rm -v "$PWD":/work -w /work alpine:3.20 ls
# lists current directory filesRun as non-root user id.
docker run --rm --user 1000:1000 alpine:3.20 id
# uid=1000 gid=1000Show processes in a container.
docker top web
# PID USER TIME COMMAND ...Live resource usage.
docker stats --no-stream web
# NAME CPU% MEM USAGE / LIMIT ...Copy files to/from a container.
docker cp web:/etc/nginx/nginx.conf ./nginx.conf
# copies config to hostRename a container.
docker rename web web-old
# web-oldDisk usage summary.
docker system df
# TYPE TOTAL ACTIVE SIZE RECLAIMABLEStack versions: Kubernetes 1.36.2 · Docker Engine 29.6.1 · Helm 3 · Compose v2 · containerd via CRI
Reviewed by Chris St. John·Last updated Jul 18, 2026