Docker Foundations·Ship the environment with the app

Images and containers

An image is a read-only template; a container is a running instance with a writable layer.

Beginner 12 min read Lesson 6 of 300 Challenge included
What you will be able to do
  • Use docker run --rm for one-off commands.
  • Pin base image versions; avoid moving latest in production.
  • Inspect a container with docker logs, exec and inspect.

In plain English

Images are built from layers. Containers add a writable layer and an isolated process. Removing a container does not remove its image. Tags such as latest are mutable; pin a digest or a specific version for repeatable deployments.

terminalTerminal
docker pull node:22-alpine
docker run --rm node:22-alpine node --version
docker run -d --name web -p 3000:3000 my-app:1.0
docker logs -f web
docker exec -it web sh
Your turn

Run a throwaway command

Easy

Run node --version in a node:22-alpine container and remove it afterwards.

BASH · starter
docker run node:22-alpine
Check your understanding before moving on.
Knowledge checkQuestion 1

What happens to changes inside a running container when it is removed?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 6 of 300 · 0% of course