🎓 A1Learner
🔍
0 of 50 lessons completed

What Is a Docker Image?

A Docker image is a read-only package of files that a container runs from. The image never changes, and each container gets its own writable layer on top.

List the images

This command lists the images on the machine.

docker images nginx --format "{{.Repository}}:{{.Tag}} {{.Size}}"

Run two containers from one image

Two containers share one image and stay separate.

docker run -d --name g4-web1 nginx:1.27-alpine
docker run -d --name g4-web2 nginx:1.27-alpine

Example

docker run -d --name g4-web1 nginx:1.27-alpine >/dev/null
docker run -d --name g4-web2 nginx:1.27-alpine >/dev/null
docker ps --format "{{.Names}} {{.Image}}"

Key points

  • Image: a read-only package with an app, its libraries and its settings.
  • Container: a running image, with one writable layer on top.
  • Many containers can run from one image at the same time.
  • A change inside a container never changes its image.
  • Images are built from a Dockerfile, or pulled from a registry.

In this example, Docker runs two containers from the same nginx image. The listing shows two names and one image. Two containers share the read-only image and keep their own writable layers apart.

Note

Read-only means the image file is never edited in place. A new build makes a new image.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What happens to an image when a container changes a file?