Three nouns cover most of Docker:
| Thing | What it is | Where it lives | Command to list |
|---|---|---|---|
| Image | Read-only files and settings for a program | Local image store (/var/lib/docker) | docker images |
| Container | A process started from an image, plus a thin writable layer | The host | docker ps -a |
| Registry | A server that stores and serves images | Network (Docker Hub by default) | docker search |
How they connect
text
registry (docker.io) this host
+---------------------+ pull +------------------+ run +--------------+
| nginx:1.27 | ------> | image nginx:1.27 | -----> | container A |
| nginx:1.26 | | (read-only) | -----> | container B |
| redis:7.4 ... | +------------------+ +--------------+
+---------------------+docker pullcopies an image from a registry to the host.docker runcreates a new container from a local image, and pulls first if the image is missing.- One image can back any number of containers. Each container gets its own writable layer; the image never changes.
Reading an image reference
text
docker.io / library / nginx : 1.27
│ │ │ └─ tag: which version (default: latest)
│ │ └──────── repository
│ └───────────────── namespace (library = official images)
└──────────────────────────── registry (default: docker.io)Docker fills in the defaults, so these name the same image:
| You type | Docker reads |
|---|---|
nginx | docker.io/library/nginx:latest |
nginx:1.27 | docker.io/library/nginx:1.27 |
stackmonsters/greeter:1.0 | docker.io/stackmonsters/greeter:1.0 |
Find, pull, list
Search Docker Hub:
sh
docker search nginxtext
NAME DESCRIPTION STARS OFFICIAL
nginx Official build of Nginx. 20500 [OK][OK] marks an . Prefer these over unknown publishers.
Pull a specific tag:
sh
docker pull nginx:1.27text
1.27: Pulling from library/nginx
0c17f8fc4ac9: Pull complete
99cdedd70cd2: Pull complete
...
Digest: sha256:461e750887eaa9bc4ce2df02120c91f5420bf6f8c99ddd609e212a8f8e65cd96
Status: Downloaded newer image for nginx:1.27
docker.io/library/nginx:1.27Each Pull complete line is a . The last line is the full reference. Pull again and Docker downloads nothing: Status: Image is up to date.
List local images:
sh
docker imagestext
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.27 9c00f3b0b0e0 2 weeks ago 192MB
hello-world latest 02bd6fe06044 18 months ago 13.3kBOne image, many containers
Run hello-world twice, then list every container, including stopped ones:
sh
docker run hello-world
docker run hello-world
docker ps -atext
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
99fddfcd7640 hello-world "/hello" 2 seconds ago Exited (0) 2 seconds ago eager_keller
e1dd94dc29ef hello-world "/hello" 4 seconds ago Exited (0) 4 seconds ago sharp_torvaldsTwo containers, each with its own ID and a generated name. docker images still shows one hello-world image.