This reference is for readers who can already connect to Docker Engine and need to look up common commands quickly. It focuses on the Docker CLI; available features may vary by Docker Desktop, Docker Engine, Compose plugin, Swarm, version, and platform. If you are new to images and containers, start with Docker Basics.
Commands are grouped by task. Do not run the page as one script. Replace angle-bracket values such as <container> before running a command; shell variables prefixed with $ must also be set in the current shell.
Connection and Environment#
| Task | Command | Notes |
|---|---|---|
| Check the client and Engine | docker version | Shows both Client and Server. Seeing only Client information usually means the Engine is not reachable. |
| Inspect Engine information | docker info | Shows details about the connected Engine, storage driver, and runtime environment. |
| Show help | docker --help; docker <command> --help | Lists top-level commands or options for a subcommand, such as docker run --help. |
| List connection targets | docker context ls | Shows Docker CLI contexts. |
| Show the current target | docker context show | Confirms which Docker Engine receives commands. |
On Linux, use the access method configured during installation, such as sudo, if your user cannot access the Docker socket. Do not ignore the root-level access granted by the docker group just to avoid sudo; see the installation guide.
Images#
| Task | Command | Notes |
|---|---|---|
| List local images | docker images | Lists images on this host; docker image ls is the corresponding management command. |
| Search Docker Hub | docker search <term> | Searches public repositories; search results are not a security or compatibility review. |
| Pull an image | docker pull <image>:<tag> | Retrieves a tagged image from a registry. Prefer the required version; latest does not mean automatic updates. |
| Tag an image | docker tag <source-image>:<tag> <registry>/<namespace>/<image>:<tag> | Adds another name to a local image; it does not duplicate or upload the image. |
| Sign in to a registry | docker login <registry> | Enter credentials when prompted. Do not put passwords directly in commands or scripts. The registry argument can be omitted for Docker Hub. |
| Push an image | docker push <registry>/<namespace>/<image>:<tag> | Pushes to a repository where you have write access. Verify the registry, namespace, and tag first. |
| Save an image archive | docker save -o image.tar <image>:<tag> | Exports an image and its related tags for offline transfer. |
| Load an image archive | docker load -i image.tar | Restores an image from an archive created by docker save. |
| Remove one local image | docker rmi <image>:<tag> | Removes a local image reference/data; removal may be blocked while a container uses it. |
docker save and docker load handle images, not container runtime state. See Getting and Distributing Docker Images for the full workflow.
Containers#
| Task | Command | Notes |
|---|---|---|
| Run a foreground container | docker run --name <name> <image>:<tag> | Displays the program output. When the program exits, the container stops but is not removed by default. |
| Run interactively | docker run --rm -it <image>:<tag> sh | -i keeps input open; -t allocates a terminal. --rm removes the container on exit. The image must include sh. |
| Run in the background | docker run -d --name <name> <image>:<tag> | Returns a container ID. The container exits when its main process ends. |
| Publish a port | docker run -d --name <name> -p 127.0.0.1:8080:80 <image>:<tag> | Maps host loopback port 8080 to container port 80. Omitting the host IP publishes on all interfaces; assess exposure first. |
| List running containers | docker ps | Stopped containers are hidden by default. |
| List all containers | docker ps -a | Includes exited containers; add --filter name=<name> to filter. Name filtering can match substrings. |
| Read container logs | docker logs <container> | Reads output written to the container’s standard output and error streams. |
| Follow logs | docker logs -f --tail 100 <container> | Starts with the last 100 lines and follows new output. Press Ctrl-C to stop following; this does not stop the container. |
| Run a command in a running container | docker exec -it <container> sh | The container must be running and include sh. |
| Inspect a container | docker inspect <container> | Prints JSON configuration and state; it may include sensitive environment variables. |
| View resource usage | docker stats | Streams CPU, memory, network, and block I/O statistics for running containers. Press Ctrl-C to exit. |
| Stop a container | docker stop <container> | Sends a stop signal, then forcefully terminates the process after the grace period. |
| Start a stopped container | docker start <container> | Starts the same existing container; it does not create a new one. |
| Remove a stopped container | docker rm <container> | Removes the container and its writable layer, not mounted volumes. Confirm its identity and data requirements first. |
The writable layer is removed with its container. Store data that must persist in a volume or bind mount; do not use docker rm -v on an unverified container. See Docker Data Persistence.
Networks and Volumes#
| Task | Command | Notes |
|---|---|---|
| List networks | docker network ls | Lists networks on the current Engine. |
| Inspect a network | docker network inspect <network> | Shows network configuration and connected endpoints. |
| Create a bridge network | docker network create <network> | Creates a bridge network by default, on the current Engine only. |
| List volumes | docker volume ls | Lists volumes managed by the current Engine. |
| Inspect a volume | docker volume inspect <volume> | Shows volume configuration, mountpoint, and other details. |
| Create a volume | docker volume create <volume> | Creates a named volume that has an independent lifecycle from containers. |
| Mount a volume in a container | docker run --mount type=volume,src=<volume>,dst=<path> <image>:<tag> | Mounts an existing volume at a container path. Only data written under that mount path goes into the volume. |
Before removing a network or volume, confirm that it is no longer needed. Removing a volume deletes its data. See the network guide and data persistence guide.
Dockerfile and Compose#
| Task | Command | Notes |
|---|---|---|
| Build an image | docker build -t <image>:<tag> <build-context> | The build context is usually the directory containing the Dockerfile. Use .dockerignore to exclude files that should not be sent. |
| Show build options | docker build --help | Build options can vary by builder and platform. |
| Validate Compose configuration | docker compose config | Merges and parses Compose configuration. Review output before sharing because interpolated secrets may appear. |
| Start a Compose project | docker compose up -d | Creates or updates services in the current Compose project and runs them in the background. |
| Build and start | docker compose up -d --build | Builds images required by the configuration before starting the project. |
| List project containers | docker compose ps | Shows container state for the current project. |
| Follow service logs | docker compose logs -f --tail 100 <service> | Follows logs for a service; <service> is its name in the Compose file. |
| Run a command in a service | docker compose exec <service> sh | Runs in an already running service container; the container must include sh. |
| Stop and remove project containers and networks | docker compose down | Does not remove named volumes or images by default. Avoid adding -v casually; it removes named volumes used by the Compose project and their data. |
The effects of rebuilding, restarting, and retaining data depend on the configuration. Start troubleshooting with docker compose config, ps, and logs. See the Compose Flask + Redis guide for a complete application workflow.
Boundaries#
- Values in
<...>are placeholders. Replace them with real values; inspect an existing resource before removing anything with a conflicting name or tag. - Docker CLI commands act on the Engine selected by the current context. With a remote context, create, remove, pull, and other operations affect that remote Engine or registry.
- This reference omits bulk cleanup commands such as
docker system pruneanddocker volume prune. They may remove resources still needed by other projects. - Check
docker <command> --helpfor options supported by your installed version. Compose configuration fields and Swarm Stack fields are not identical; do not use Compose commands here as a Stack deployment workflow.