Docker Commands any self-respected Docker expert MUST know

Published Updated

15 min read

Many Docker guides online were written for versions that are long gone: flags were removed, output formats changed, and habits like committing containers or logging in with an email no longer work. This guide covers the Docker commands you'll use every day, from pulling and running images to building, pushing, composing and cleaning up, with real output from a current Docker Engine.


The Docker CLI is self-documenting. To see every command available in your installation, run:

shell

1docker --help

To see the options of a single command, add --help after it. For example, for docker run:

shell

1docker run --help

All commands and outputs below were run on Docker Engine 29.9 on Linux, and the core flow was repeated in Docker Desktop on a Mac. Each section builds on the previous one, so you can follow the whole guide in a terminal from top to bottom. Where an output is long, we cut it and mark the cut with three dots (…).

Docker commands cheat sheet

Here are the commands this guide covers, grouped by what you do with them. The full list lives in the Docker CLI reference.

System
  • docker version - client and server versions.
  • docker info - system-wide information: containers, images, storage driver, resources.
  • docker system df - how much disk space images, containers, volumes and build cache use.
  • docker system prune - remove everything unused.
Images
  • docker search - search Docker Hub for images.
  • docker pull - download an image from a registry.
  • docker images - list local images (same as docker image ls).
  • docker history - show the layers an image was built from.
  • docker build - build an image from a Dockerfile.
  • docker tag - give an image another name, for example for a registry.
  • docker push - upload an image to a registry.
  • docker rmi - remove images.
Containers
  • docker run - create and start a container from an image.
  • docker ps - list running containers; docker ps -a lists all of them.
  • docker start, docker stop, docker restart - control the container lifecycle.
  • docker kill - stop a container immediately.
  • docker logs - show what the container wrote to stdout and stderr.
  • docker exec - run a command, or a shell, inside a running container.
  • docker attach - connect your terminal to the container's main process.
  • docker inspect - low-level details about a container, image, network or volume.
  • docker port, docker stats - published ports and live resource usage.
  • docker cp - copy files between your machine and a container.
  • docker rm - remove containers.
Registries
  • docker login, docker logout - authenticate to Docker Hub or another registry.
Networks and volumes
  • docker network create, docker network ls, docker network rm
  • docker volume create, docker volume ls, docker volume rm
Compose
  • docker compose up, docker compose ps, docker compose logs, docker compose exec, docker compose down

Most short commands have a longer "management" form that groups commands by object: docker ps is docker container ls, docker images is docker image ls, docker rmi is docker image rm. Both forms work, so use whichever you remember.

Check the Docker version and system information

Whether you work on a laptop or a cloud server, the first thing to check is which Docker you're talking to:

shell

1$ docker version
2Client:
3 Version: 29.9.2
4 API version: 1.56
5 Go version: go1.26.10
6 Git commit: a82e528
7 Built: Tue Oct 20 18:43:37 2026
8 OS/Arch: linux/arm64
9 Context: default
10
11Server: Docker Engine - Community
12 Engine:
13 Version: 29.9.2
14 API version: 1.56 (minimum version 1.40)
15 Go version: go1.26.10
16 Git commit: 0367cbe
17 Built: Tue Oct 20 18:44:59 2026
18 OS/Arch: linux/arm64
19 Experimental: false
20 containerd:
21 Version: v2.4.2
22 GitCommit:
23 runc:
24 Version: 1.5.2
25 GitCommit: v1.5.2-0-g29dd3dc
26 docker-init:
27 Version: 0.19.0
28 GitCommit: de40ad0

The output has two parts. The client is the docker command you type, and the server is the Docker Engine that actually runs containers. They can be on different machines and different versions.

In Docker Desktop, the server line reads Server: Docker Desktop followed by the Desktop version.

For the bigger picture, use docker info:

shell

1$ docker info
2Client:
3 Version: 29.9.2
4 Context: default
5 Debug Mode: false
6 Plugins:
7 buildx: Docker Buildx (Docker Inc.)
8 Version: v0.38.1
9 Path: /usr/local/libexec/docker/cli-plugins/docker-buildx
10 compose: Docker Compose (Docker Inc.)
11 Version: v5.6.1
12 Path: /usr/local/libexec/docker/cli-plugins/docker-compose
13
14Server:
15 Containers: 0
16 Running: 0
17 Paused: 0
18 Stopped: 0
19 Images: 0
20 Server Version: 29.9.2
21 Storage Driver: overlayfs
22 driver-type: io.containerd.snapshotter.v1
23 Logging Driver: json-file
24 Cgroup Driver: cgroupfs
25 Cgroup Version: 2
26…
27 Kernel Version: 6.12.76-linuxkit
28 Operating System: Alpine Linux v3.24 (containerized)
29 OSType: linux
30 Architecture: aarch64
31 CPUs: 10
32 Total Memory: 7.75GiB
33…

It shows how many containers are running, paused and stopped, how many images you have, the storage driver, the kernel, and how much CPU and memory the engine can use. That's the first place to look when containers run out of memory or disk, or when you need to know whether the Compose and Buildx plugins are installed.

Search and pull images

You can search Docker Hub right from the terminal:

shell

1$ docker search --limit 5 ubuntu
2NAME DESCRIPTION STARS OFFICIAL
3ubuntu Ubuntu is a Debian-based Linux operating sys… 17873 [OK]
4ubuntu/squid Squid is a caching proxy for the Web. Long-t… 131
5ubuntu/nginx Nginx, a high-performance reverse proxy & we… 143
6ubuntu/kafka Apache Kafka, a distributed event streaming … 62
7ubuntu/bind9 BIND 9 is a very flexible, full-featured DNS… 121

Stars show popularity, and [OK] in the OFFICIAL column marks a Docker Official Image, a curated image that Docker reviews and publishes. To see only official images, add a filter:

shell

1$ docker search --filter is-official=true --limit 3 nginx
2NAME DESCRIPTION STARS OFFICIAL
3nginx Official build of Nginx. 21414 [OK]

Download the official Ubuntu image with docker pull:

shell

1$ docker pull ubuntu
2Using default tag: latest
3latest: Pulling from library/ubuntu
4…
5Digest: sha256:6a06111c3b0a8600feadb270aec771dc239bf407b25625f93f44ab00e11f4d3c
6Status: Downloaded newer image for ubuntu:latest
7docker.io/library/ubuntu:latest

Without a tag, Docker pulls latest. For Ubuntu, latest points to the newest LTS release, which you can check by running a throwaway container:

shell

1$ docker run --rm ubuntu grep PRETTY_NAME /etc/os-release
2PRETTY_NAME="Ubuntu 26.04.1 LTS"

latest moves when a new release comes out, so for anything you deploy, pin a tag. To get Ubuntu 24.04 LTS, pull it by tag:

shell

1$ docker pull ubuntu:24.04
224.04: Pulling from library/ubuntu
3…
4Status: Downloaded newer image for ubuntu:24.04
5docker.io/library/ubuntu:24.04

Pull NGINX too, we'll use it in the next sections:

shell

1docker pull nginx

Now list your local images:

shell

1$ docker images
2IMAGE ID DISK USAGE CONTENT SIZE EXTRA
3nginx:latest 5ab5b0b01097 261MB 65.1MB
4ubuntu:24.04 fe81560990fa 141MB 30.9MB
5ubuntu:latest 6a06111c3b0a 181MB 44.9MB

The available tags for each image are listed on its Docker Hub page, for example Ubuntu and NGINX.

You don't need a Docker Hub account to pull public images. Anonymous pulls are limited to 100 per 6 hours per IP address, and a free account doubles that, according to the Docker Hub usage docs. On a shared CI runner, log in to avoid hitting the limit.

Run a container

Start an NGINX container in the background, publish its port 80 on port 8080 of your machine, and give it a name:

shell

1$ docker run -d -p 8080:80 --name web nginx
2e1643f43bdd35c03824d7b9c9d81ad7b6ee1b909d4259deea1033685fd1d53ed
  • -d (detached) runs the container in the background and prints its ID. Without it, the container is attached to your terminal and stops when you press Ctrl+C.
  • -p 8080:80 sends traffic from port 8080 on your machine to port 80 in the container. More on that in our guide on how to expose a port in a Docker container.
  • --name web gives the container a name you can use in every other command.

Check that NGINX answers on http://localhost:8080:

shell

1$ curl -sI http://localhost:8080
2HTTP/1.1 200 OK
3Server: nginx/1.31.8
4Date: Mon, 02 Nov 2026 13:18:22 GMT
5Content-Type: text/html
6Content-Length: 896
7Last-Modified: Wed, 21 Oct 2026 14:24:51 GMT
8Connection: keep-alive
9ETag: "6ad8cb33-380"
10Accept-Ranges: bytes

Start a second NGINX container, this time without a name:

shell

1$ docker run -d -p 8081:80 nginx
27f61bf93cbae366a489bfc9cf5af02f82f6379e52c37d7e2c7265e4792eecffb

List containers with docker ps

docker ps shows the running containers:

shell

1$ docker ps
2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
37f61bf93cbae nginx "/docker-entrypoint.…" 2 seconds ago Up 1 second 0.0.0.0:8081->80/tcp, [::]:8081->80/tcp condescending_banzai
4e1643f43bdd3 nginx "/docker-entrypoint.…" 4 seconds ago Up 3 seconds 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp web

You see the image, the command, the status and the port mappings. Every command accepts either the CONTAINER ID (the first few characters are enough) or the NAME.

The second container got a random name, condescending_banzai. Yours will be different, so use your own name in the commands below. When you work with many containers, name them yourself with --name and a naming convention.

docker ps only lists running containers. Add -a to see stopped ones too, as you'll see in the next section.

Start, stop, restart and kill containers

Stop the second container:

shell

1$ docker stop condescending_banzai
2condescending_banzai

Now compare docker ps -a with the previous output:

shell

1$ docker ps -a
2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
37f61bf93cbae nginx "/docker-entrypoint.…" 2 seconds ago Exited (0) Less than a second ago condescending_banzai
4e1643f43bdd3 nginx "/docker-entrypoint.…" 4 seconds ago Up 3 seconds 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp web

The stopped container is still there, with status Exited (0). docker stop sends the container's stop signal, waits up to 10 seconds for a clean shutdown, and only then kills it.

Start it again, and restart the web container in one go:

shell

1$ docker start condescending_banzai
2condescending_banzai
3$ docker restart web
4web

docker kill doesn't wait. It sends SIGKILL right away, like kill -9 for a process:

shell

1$ docker kill condescending_banzai
2condescending_banzai

shell

1$ docker ps -a
2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
37f61bf93cbae nginx "/docker-entrypoint.…" 2 seconds ago Exited (137) Less than a second ago condescending_banzai
4e1643f43bdd3 nginx "/docker-entrypoint.…" 4 seconds ago Up Less than a second 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp web

Exit code 137 means the process was killed (128 + signal 9). Use docker kill for a container that ignores docker stop, and docker start brings it back.

View container logs

Whatever the main process writes to stdout and stderr ends up in docker logs:

shell

1$ docker logs --tail 3 web
22026/11/02 13:18:24 [notice] 1#1: start worker process 29
32026/11/02 13:18:24 [notice] 1#1: start worker process 30
42026/11/02 13:18:24 [notice] 1#1: start worker process 31

The flags you'll use most:

  • -f follows the log live, like tail -f;
  • --tail 100 shows only the last 100 lines;
  • --since 10m shows the last 10 minutes;
  • -t adds timestamps.

That's why official images send their logs to stdout: you read them with docker logs instead of looking for files inside the container.

Open a shell in a container with docker exec

You'll often need a shell inside a container to check a config or debug a problem. There's no need for SSH: Docker gives you a shell directly.

First, start an Ubuntu container with an interactive bash shell:

shell

1$ docker run -it --name my_ubuntu ubuntu:24.04 bash
2root@25828d357116:/# grep PRETTY_NAME /etc/os-release
3PRETTY_NAME="Ubuntu 24.04.5 LTS"
4root@25828d357116:/# pwd
5/
6root@25828d357116:/# exit
7exit

-i keeps input open and -t gives you a terminal. The prompt root@25828d357116 shows the container ID as the hostname.

Here bash is the container's main process, so exit stops the container:

shell

1$ docker ps -a --filter name=my_ubuntu
2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
325828d357116 ubuntu:24.04 "bash" 3 seconds ago Exited (0) Less than a second ago my_ubuntu

Start it again. It keeps running in the background with bash waiting for input:

shell

1$ docker start my_ubuntu
2my_ubuntu

Now open a second shell inside the running container with docker exec:

shell

1$ docker exec -it my_ubuntu bash
2root@25828d357116:/# ps aux
3USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
4root 1 0.0 0.0 4300 3632 pts/0 Ss+ 13:18 0:00 bash
5root 9 0.0 0.0 4300 3640 pts/1 Ss 13:18 0:00 bash
6root 17 0.0 0.0 7632 3656 pts/1 R+ 13:18 0:00 ps aux
7root@25828d357116:/# exit
8exit

ps aux shows the difference. PID 1 is the container's main process, and your docker exec shell is a separate process (PID 9). When you exit it, the container keeps running:

shell

1$ docker ps --filter name=my_ubuntu
2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
325828d357116 ubuntu:24.04 "bash" 5 seconds ago Up 2 seconds my_ubuntu

You don't need a shell to run a single command. Drop -it and pass the command:

shell

1$ docker exec my_ubuntu ls /
2bin
3boot
4dev
5etc
6…
7usr
8var

What -i, -t and -d do. docker exec always attaches the command's stdout and stderr to your terminal. That's why the ls output above appears without any flags.

-i also connects your stdin, so you can pipe data into the command: echo hello | docker exec my_ubuntu cat prints nothing, while echo hello | docker exec -i my_ubuntu cat prints hello.

-t allocates a terminal, which an interactive shell needs. -d runs the command in the background and returns right away.

The errors you'll meet most often with docker exec:

  • Error response from daemon: container … is not running. docker exec only works on running containers. Start the container first. If it crashes on start, read docker logs, and pull files out with docker cp, which works on stopped containers too.
  • exec: "bash": executable file not found in $PATH. The image has no bash, which is normal for Alpine and other minimal images. Use sh instead. Distroless images have no shell at all, so debug them from outside with docker logs, docker inspect and docker cp.
  • cannot attach stdin to a TTY-enabled container because stdin is not a terminal. You used -t in a script, a pipe or a CI job. Drop -t and keep -i if you need stdin.

Run containers in detached mode and use docker attach

You can start an interactive container in the background right away by adding -d to -it:

shell

1$ docker run -dit --name my_ubuntu_2 ubuntu:24.04 bash
28300f8c500cc29da872d523c42ec47fe3a2304e1ad37583b1948918fad88c594

docker attach connects your terminal to the container's main process, the same bash you started:

shell

1$ docker attach my_ubuntu_2
2root@8300f8c500cc:/# read escape sequence

The important part is how you leave. Type exit and you end the main process, so the container stops.

To detach and leave it running, press Ctrl+P and then Ctrl+Q. Docker prints read escape sequence, and the container is still up:

shell

1$ docker ps --filter name=my_ubuntu_2
2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
38300f8c500cc ubuntu:24.04 "bash" 2 seconds ago Up 2 seconds my_ubuntu_2

For day-to-day work, docker exec is the safer choice. Use docker attach when you need the main process itself, for example to answer a prompt in an interactive program. The docker attach reference explains how to change the detach keys.

Inspect containers and images

docker inspect returns everything Docker knows about an object as JSON:

shell

1$ docker inspect web | head -12
2[
3 {
4 "Id": "e1643f43bdd35c03824d7b9c9d81ad7b6ee1b909d4259deea1033685fd1d53ed",
5 "Created": "2026-11-02T13:18:20.493622343Z",
6 "Path": "/docker-entrypoint.sh",
7 "Args": [
8 "nginx",
9 "-g",
10 "daemon off;"
11 ],
12 "State": {
13 "Status": "running",
14…

The full output runs to hundreds of lines. Instead of scrolling through it, ask for the one field you need with --format. Here's the container's IP address:

shell

1$ docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' web
2172.18.0.2

Two related commands answer the most common questions faster. docker port shows the published ports, and docker stats shows CPU, memory and network usage:

shell

1$ docker port web
280/tcp -> 0.0.0.0:8080
380/tcp -> [::]:8080

shell

1$ docker stats --no-stream web
2CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
3e1643f43bdd3 web 0.00% 8.777MiB / 7.75GiB 0.11% 922B / 126B 0B / 4.1kB 11

Without --no-stream, docker stats keeps updating until you press Ctrl+C.

Check the history of an image

Images are built in layers, one per Dockerfile instruction. docker history shows those layers:

shell

1$ docker history nginx
2IMAGE CREATED CREATED BY SIZE COMMENT
35ab5b0b01097 5 days ago CMD ["nginx" "-g" "daemon off;"] 0B buildkit.dockerfile.v0
4<missing> 5 days ago STOPSIGNAL SIGQUIT 0B buildkit.dockerfile.v0
5<missing> 5 days ago EXPOSE map[80/tcp:{}] 0B buildkit.dockerfile.v0
6<missing> 5 days ago ENTRYPOINT ["/docker-entrypoint.sh"] 0B buildkit.dockerfile.v0
7<missing> 5 days ago COPY 30-tune-worker-processes.sh /docker-ent… 16.4kB buildkit.dockerfile.v0
8<missing> 5 days ago COPY 20-envsubst-on-templates.sh /docker-ent… 12.3kB buildkit.dockerfile.v0
9<missing> 5 days ago COPY 15-local-resolvers.envsh /docker-entryp… 12.3kB buildkit.dockerfile.v0
10<missing> 5 days ago COPY 10-listen-on-ipv6-by-default.sh /docker… 12.3kB buildkit.dockerfile.v0
11<missing> 5 days ago COPY docker-entrypoint.sh / # buildkit 8.19kB buildkit.dockerfile.v0
12<missing> 5 days ago RUN /bin/sh -c set -x && groupadd --syst… 86.6MB buildkit.dockerfile.v0
13<missing> 5 days ago ENV DYNPKG_RELEASE=1~trixie 0B buildkit.dockerfile.v0
14<missing> 5 days ago ENV PKG_RELEASE=1~trixie 0B buildkit.dockerfile.v0
15<missing> 5 days ago ENV ACME_VERSION=0.4.1 0B buildkit.dockerfile.v0
16<missing> 5 days ago ENV NJS_RELEASE=1~trixie 0B buildkit.dockerfile.v0
17<missing> 5 days ago ENV NJS_VERSION=1.0.2 0B buildkit.dockerfile.v0
18<missing> 5 days ago ENV NGINX_VERSION=1.31.8 0B buildkit.dockerfile.v0
19<missing> 5 days ago LABEL maintainer=NGINX Docker Maintainers <d… 0B buildkit.dockerfile.v0
20<missing> 6 days ago # debian.sh --arch 'arm64' out/ 'trixie' '@1… 110MB debuerreotype 0.17

<missing> isn't an error. Layers that were built elsewhere and pulled from a registry don't have local image IDs.

The history tells you what changed between versions, which helps when a container breaks after an image update. Add --no-trunc to see the full commands. docker image history nginx is the same command in the long form.

Copy files with docker cp

Let's replace the NGINX welcome page in the web container. Create index.html in your current directory:

html

1<!DOCTYPE html>
2<html>
3<head><title>My Website</title></head>
4<body>
5Hello world
6</body>
7</html>

Check what's in the NGINX web root:

shell

1$ docker exec web ls /usr/share/nginx/html
250x.html
3index.html

Copy your file over the default one. docker cp prints nothing when it succeeds:

shell

1docker cp index.html web:/usr/share/nginx/html/index.html

Now http://localhost:8080 serves your page:

shell

1$ curl -s http://localhost:8080
2<!DOCTYPE html>
3<html>
4<head><title>My Website</title></head>
5<body>
6Hello world
7</body>
8</html>

docker cp works in both directions: docker cp web:/etc/nginx/conf.d/default.conf . copies a file out of the container.

It's handy for debugging, but the change lives only in this container. Remove the container and the file is gone. For a change you want to keep, build an image.

Build your own image with a Dockerfile

To get more "Hello world" containers, put the change in a Dockerfile. Create a file named Dockerfile next to index.html:

dockerfile

1FROM nginx:1.31-alpine
2COPY index.html /usr/share/nginx/html/index.html

FROM sets the base image, pinned to a version so the build gives the same result next month. COPY adds your page on top. Build the image and tag it hello-web:1.0:

shell

1$ docker build -t hello-web:1.0 .
2#0 building with "default" instance using docker driver
3…
4#5 [1/2] FROM docker.io/library/nginx:1.31-alpine@sha256:785835ea65db4bba6f021acc0f3be91b0fef76a53fe41f8588c6698d2aed0606
5#5 DONE 1.4s
6
7#6 [2/2] COPY index.html /usr/share/nginx/html/index.html
8#6 DONE 0.1s
9
10#7 exporting to image
11…
12#7 naming to docker.io/library/hello-web:1.0 done
13#7 unpacking to docker.io/library/hello-web:1.0 0.3s done
14#7 DONE 0.3s

The dot at the end is the build context, the folder whose files the Dockerfile can copy. The command fails without it.

shell

1$ docker images hello-web
2IMAGE ID DISK USAGE CONTENT SIZE EXTRA
3hello-web:1.0 74314a40ea3e 93.2MB 26.3MB

Every container you start from this image serves your page:

shell

1$ docker run -d -p 8082:80 --name hello hello-web:1.0
2722cd3d8ffadb5ee75deb70e08a112e2ff7b10d3c2d0db9ac3ea905bfac28082
3$ curl -s http://localhost:8082
4<!DOCTYPE html>
5<html>
6<head><title>My Website</title></head>
7<body>
8Hello world
9</body>
10</html>

What about docker commit? It still exists and saves a container's current state as an image, for example docker commit web web-snapshot. But nobody can see or repeat how that image was made, and it carries whatever else changed in the container: caches, logs, temp files. Use it to save a broken container for later debugging.

For anything you ship, use a Dockerfile: it's versioned in git, reviewed, and rebuilt the same way every time. The Dockerfile best practices cover the rest, and our guide on how to run a Docker container on your local machine builds and runs a real app image step by step.

Tag, log in and push to a registry

To share an image, push it to a registry. For Docker Hub, log in with:

shell

1docker login

Docker opens a web-based sign-in and shows a one-time device code to confirm in the browser.

On a server or in CI, sign in with a username and a personal access token (PAT) instead of your password. Create the token in your Docker Hub account settings, as described in the access tokens docs, and pass it on stdin so it doesn't end up in your shell history:

shell

1echo "$DOCKERHUB_TOKEN" | docker login --username yourhubusername --password-stdin

Old guides show docker login with --email. That flag was removed in Docker 17.06, and today it fails:

shell

1$ docker login --username demo --email demo@example.com
2unknown flag: --email
3
4Usage: docker login [OPTIONS] [SERVER]
5
6Run 'docker login --help' for more information

To try the whole push flow without a Docker Hub account, run a private registry locally. The official registry:3 image does that. First, create a user demo with the password demo-password in an htpasswd file:

shell

1mkdir -p auth && docker run --rm --entrypoint htpasswd httpd:2.4 -Bbn demo demo-password > auth/htpasswd

Start the registry on port 5000 with password authentication:

shell

1docker run -d -p 5000:5000 --name registry -v "$PWD/auth:/auth" -e REGISTRY_AUTH=htpasswd -e REGISTRY_AUTH_HTPASSWD_REALM=Registry -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry:3

An image goes to the registry that its name points to. Tag hello-web:1.0 with the registry address:

shell

1docker tag hello-web:1.0 localhost:5000/hello-web:1.0

Pushing before you log in fails:

shell

1$ docker push localhost:5000/hello-web:1.0
2The push refers to repository [localhost:5000/hello-web]
3push access denied, repository does not exist or may require authorization: authorization failed: no basic auth credentials

Log in with the password on stdin:

shell

1$ export REGISTRY_PASSWORD=demo-password
2$ echo "$REGISTRY_PASSWORD" | docker login localhost:5000 --username demo --password-stdin
3
4WARNING! Your credentials are stored unencrypted in '/root/.docker/config.json'.
5Configure a credential helper to remove this warning. See
6https://docs.docker.com/go/credential-store/
7
8Login Succeeded

The warning matters on servers: without a credential helper, Docker saves the credentials base64-encoded, not encrypted. Docker Desktop uses the system keychain by default. On Linux, set up a credential store or log out when you're done.

Now the push works:

shell

1$ docker push localhost:5000/hello-web:1.0
2The push refers to repository [localhost:5000/hello-web]
3567a969e0221: Pushed
4…
5cbe54b031f3e: Pushed
61.0: digest: sha256:74314a40ea3ed55d62b7a652250da8c21e7230e1ca8357af4298ed495cb414f0 size: 856

To check, remove the local tag and pull the image back from the registry:

shell

1$ docker rmi localhost:5000/hello-web:1.0
2Untagged: localhost:5000/hello-web:1.0
3$ docker pull localhost:5000/hello-web:1.0
41.0: Pulling from hello-web
5Digest: sha256:74314a40ea3ed55d62b7a652250da8c21e7230e1ca8357af4298ed495cb414f0
6Status: Downloaded newer image for localhost:5000/hello-web:1.0
7localhost:5000/hello-web:1.0

Log out to remove the stored credentials:

shell

1$ docker logout localhost:5000
2Removing login credentials for localhost:5000

For Docker Hub, the flow is the same, only the image name changes: docker tag hello-web:1.0 yourhubusername/hello-web:1.0, then docker push yourhubusername/hello-web:1.0.

Connect containers with networks and volumes

Containers on the same user-defined network find each other by name, and a volume keeps data after the container is gone. Create both:

shell

1$ docker network create app-net
2f0947cc37c65a53aeda2c7c26ee56e854dbd480a362f62de41ee0bede91419b1
3$ docker volume create cache-data
4cache-data

Start Redis on that network, with its data in the volume:

shell

1docker run -d --name cache --network app-net -v cache-data:/data redis:8-alpine

Any other container on app-net reaches it by the name cache:

shell

1$ docker run --rm --network app-net redis:8-alpine redis-cli -h cache ping
2PONG

--rm removes this one-off container as soon as the command finishes. List networks and volumes with ls:

shell

1$ docker network ls
2NETWORK ID NAME DRIVER SCOPE
3f0947cc37c65 app-net bridge local
438993e6149f8 bridge bridge local
56cb39cba9523 host host local
6d5b80360d6e8 none null local

shell

1$ docker volume ls
2DRIVER VOLUME NAME
3local 40cf6939646ee5f530f6a8551955c3ab99dac5f6f81606468c4225c1e99a84c7
4local cache-data

The volume with a long random name is an anonymous volume. The registry image created it for its data. Name resolution doesn't work on the default bridge network, which is one more reason to create your own.

Run multi-container apps with docker compose

Typing long docker run commands for every container gets old fast. Docker Compose describes the whole set in one file. Create compose.yaml next to your Dockerfile:

yaml

1services:
2 web:
3 build: .
4 ports:
5 - "8083:80"
6 depends_on:
7 - cache
8 cache:
9 image: redis:8-alpine
10 volumes:
11 - cache-data:/data
12
13volumes:
14 cache-data:

Build and start everything in the background:

shell

1$ docker compose up -d --build
2 Image project-web Building
3…
4 Image project-web Built
5…
6 Container project-cache-1 Started
7 Container project-web-1 Starting
8 Container project-web-1 Started

Compose created a network for the project, a volume, built the web image from your Dockerfile and started both containers. It names everything after the project folder, project in our case. The everyday commands mirror the ones you already know:

shell

1$ docker compose ps
2NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
3project-cache-1 redis:8-alpine "docker-entrypoint.s…" cache 2 seconds ago Up 2 seconds 6379/tcp
4project-web-1 project-web "/docker-entrypoint.…" web 2 seconds ago Up 2 seconds 0.0.0.0:8083->80/tcp, [::]:8083->80/tcp

shell

1$ curl -s http://localhost:8083
2<!DOCTYPE html>
3<html>
4<head><title>My Website</title></head>
5<body>
6Hello world
7</body>
8</html>

shell

1$ docker compose exec cache redis-cli ping
2PONG

shell

1$ docker compose logs --tail 2 cache
2cache-1 | 1:M 02 Nov 2026 13:18:51.675 * Ready to accept connections tcp
3cache-1 | 1:M 02 Nov 2026 13:18:51.675 # WARNING: Redis does not require authentication and is not protected by network restrictions. Redis will accept connections from any IP address on any network interface.

Stop and remove the containers and the network. --volumes removes the volume too, so leave it out when you want to keep the data:

shell

1$ docker compose down --volumes
2 Container project-web-1 Stopping
3 Container project-web-1 Stopped
4 Container project-web-1 Removing
5 Container project-web-1 Removed
6 Container project-cache-1 Stopping
7 Container project-cache-1 Stopped
8 Container project-cache-1 Removing
9 Container project-cache-1 Removed
10 Volume project_cache-data Removing
11 Network project_default Removing
12 Volume project_cache-data Removed
13 Network project_default Removed

Note the space: docker compose, not docker-compose. The hyphenated command is the old standalone Compose v1.

Current Docker ships Compose as a CLI plugin, and the compose line in docker info shows its version. More in the Docker Compose docs.

Remove containers, images and everything unused

Containers, images, volumes and build cache take disk space. See how much with docker system df:

shell

1$ docker system df
2TYPE TOTAL ACTIVE SIZE RECLAIMABLE
3Images 8 5 974.6MB 248.8MB (25%)
4Containers 7 6 323.6kB 81.92kB (25%)
5Local Volumes 2 2 26.28MB 0B (0%)
6Build Cache 12 0 93.23MB 20.48kB

Remove containers

Here's everything this guide has started:

shell

1$ docker ps -a
2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3218eaebc80b0 redis:8-alpine "docker-entrypoint.s…" 6 seconds ago Up 5 seconds 6379/tcp cache
48bbd9557c437 registry:3 "/entrypoint.sh /etc…" 12 seconds ago Up 12 seconds 0.0.0.0:5000->5000/tcp, [::]:5000->5000/tcp registry
5722cd3d8ffad hello-web:1.0 "/docker-entrypoint.…" 19 seconds ago Up 18 seconds 0.0.0.0:8082->80/tcp, [::]:8082->80/tcp hello
68300f8c500cc ubuntu:24.04 "bash" 25 seconds ago Up 25 seconds my_ubuntu_2
725828d357116 ubuntu:24.04 "bash" 30 seconds ago Up 27 seconds my_ubuntu
87f61bf93cbae nginx "/docker-entrypoint.…" 32 seconds ago Exited (137) 29 seconds ago condescending_banzai
9e1643f43bdd3 nginx "/docker-entrypoint.…" 34 seconds ago Up 30 seconds 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp web

docker rm refuses to remove a running container:

shell

1$ docker rm web
2Error response from daemon: cannot remove container "web": container is running: stop the container before removing or force remove

Stop the running ones first, then remove them all. Both commands take several names or IDs at once:

shell

1$ docker stop web hello my_ubuntu my_ubuntu_2 cache registry
2web
3hello
4my_ubuntu
5my_ubuntu_2
6cache
7registry

shell

1$ docker rm web hello my_ubuntu my_ubuntu_2 condescending_banzai cache registry
2web
3hello
4my_ubuntu
5my_ubuntu_2
6condescending_banzai
7cache
8registry

docker rm -f stops and removes in one step. It's a kill, not a clean shutdown, so keep it for containers you don't care about:

shell

1$ docker run -d --name tmp nginx
234dd1754dabef3e6b3cd883b9f366d46317f4d541de470de444bfa96c8bc80ea
3$ docker rm -f tmp
4tmp

Remove images, volumes and networks

shell

1$ docker rmi localhost:5000/hello-web:1.0 hello-web:1.0
2Untagged: localhost:5000/hello-web:1.0
3Untagged: hello-web:1.0
4Deleted: sha256:74314a40ea3ed55d62b7a652250da8c21e7230e1ca8357af4298ed495cb414f0

Both tags pointed to the same image, so the image itself is deleted only when its last tag goes. Volumes and networks are removed by name:

shell

1$ docker volume rm cache-data
2cache-data
3$ docker network rm app-net
4app-net

Prune everything unused

docker system prune removes stopped containers, unused networks, dangling images and unused build cache:

shell

1$ docker system prune -f
2Deleted build cache objects:
3u60dcdfn0hkq80p5l2xybo4no
4exlqpdkmsknpg7bhor0pgdl4k
5fbqe3rg4le4ni1frbenmay0ov
6
7Total reclaimed space: 20.48kB

Add -a to also remove every image that no container uses, and --volumes for anonymous volumes:

shell

1$ docker system prune -a --volumes -f
2Deleted Volumes:
340cf6939646ee5f530f6a8551955c3ab99dac5f6f81606468c4225c1e99a84c7
4
5Deleted Images:
6untagged: registry:3
7…
8untagged: redis:8-alpine
9…
10
11Total reclaimed space: 1.068GB

Without -f, Docker lists what it's about to delete and asks for confirmation. Read that list.

The prune commands work on the whole machine, not on one project. On a laptop or server shared with other projects, prune -a also deletes their images, and the next start pulls them again. When in doubt, remove your own containers and images by name, as above.

Now the engine is empty again:

shell

1$ docker ps -a
2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3$ docker images
4IMAGE ID DISK USAGE CONTENT SIZE EXTRA

Wrapping up

These commands cover most of a Docker workday:

  • run, ps and logs to start and watch containers;
  • exec to get inside;
  • inspect to dig deeper;
  • build and push to ship images;
  • compose for multi-container apps;
  • rm, rmi and prune to clean up.

When a flag doesn't work the way an old guide says, docker <command> --help shows what your version supports.

Want to go deeper on a single topic? See how to expose a port in a Docker container, how to run a Docker container on your local machine, and connecting to the Docker host from a Docker container.

Once your containers move from a laptop to production, the questions change: orchestration, scaling, security, cost. If you're planning that step, our Kubernetes consulting team can help you get there without the usual detours.

Alex Kondratiev

Alex Kondratiev

Founder and CEO of ITsyndicate. DevOps engineer with 15+ years in cloud infrastructure, Infrastructure as Code, Kubernetes and automation, focused on secure, scalable and resilient systems.

More about Alex

An Infrastructure Review Should Give You a Plan, Not a Dependency

Why we want the review to be useful even if your own team does all the work afterward. Of course we want to help with the implementation. We are an engineering company. We like solving infrastructure problems, and we want relationships where we can take responsibility for the work over time. So why offer an Infrastructure Review that a client can take back to their own team? Because I want the first engagement to earn its fee on its own. The client should leave with a better understanding of their situation, clear priorities, and a practical next step. They can then decide whether they want us to carry out the changes. That is the principle behind how we are building our Infrastructure Review. It shapes what we agree to investigate, how we explain our findings, and what the client can do with them afterward.

Your Infrastructure Can Be Expensive Even When Nothing Is Broken

A quiet production environment can still hide rising costs, wasted engineering capacity, and risks that appear only during growth or recovery. A familiar weekly update sounds like this: production is stable, the latest release went out, and there were no serious customer complaints. The cloud bill is higher again, but there is probably a reasonable explanation. One engineer spent half a day helping with the release, another fixed a monitoring issue, and the database may need attention next quarter. Nothing is broken badly enough to become a leadership problem. That is exactly why the underlying problem can survive for so long. I have seen this pattern more than once. Production looks stable, while senior engineers quietly spend much of their time keeping it that way. The platform works, but the company is paying for that stability through cloud spend, manual effort, slower releases, and assumptions about growth or recovery that nobody has tested recently. Infrastructure doesn’t need to cause an outage to become expensive. Outages are obvious. Inefficiency is quieter, and it can keep working for years while charging you for the privilege.

How to Run a Docker Container on Your Local Machine

This article is a quick, hands-on guide to running Docker locally. It walks through essential CLI commands for managing images and containers (build, pull, run, ps, start/stop, rm/rmi) and shows how to automate image creation with a Dockerfile. You’ll build an image, run a container with port mapping, verify it’s running, and learn tips for environment setup - everything you need to spin up and manage local containers efficiently.

Stay online.
Stay in command.