Images vs Containers

Beginner

Overview

An image is a read-only template (your app plus its dependencies). A container is a running instance of an image — you can start many containers from one image.

docker pull downloads an image from a registry like Docker Hub. docker run creates and starts a container from it. docker ps lists running containers.

Containers are ephemeral: when one stops, changes inside it are lost unless you used a volume (covered later).

Cheatsheet

docker pull nginxDownload an image
docker run -d -p 8080:80 nginxRun detached, map a port
docker psList running containers
docker ps -aList all containers, including stopped
docker imagesList local images
docker stop <id>Stop a running container

Try it

A safe, simulated terminal. Run the suggested commands to see typical output.

simulated terminal

Type a command and press Enter, or click a suggestion below to run it.

$

Quick quiz

1. What is the relationship between an image and a container?

2. Which flag runs a container in the background?