Skip to content

Running Containers

An image is a blueprint. A container is a live, running instance of that blueprint — an isolated process with its own filesystem, network, and process space, all sharing the host kernel.

You can run many containers from the same image, stop and restart them, inspect their logs, and remove them when you are done. Understanding this lifecycle is the foundation of working with Docker day to day.

Every container moves through four states:

StateWhat it means
Createddocker create allocated the container but it has not started yet.
RunningThe container’s main process is executing.
StoppedThe main process exited (or you called docker stop). The container still exists on disk.
Removeddocker rm deleted the container and freed its writable layer.
docker run → Created + Running
docker stop → Stopped
docker start → Running again
docker rm → Removed (gone)
LessonTopic
Lifecycledocker run, docker ps, docker stop/start/restart, docker rm, --rm
Exec & Logsdocker exec -it, docker logs, docker top, attaching
Ports & EnvPublishing ports -p, environment variables -e, naming --name
Restart & InspectRestart policies, docker inspect, docker stats, resource limits

The three commands you will use most in this module:

Terminal window
# Pull and run nginx in the background
docker run -d --name demo nginx:alpine
# List running containers
docker ps
# Stop it
docker stop demo
# Remove it
docker rm demo
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1b2c3d4e5f6 nginx:alpine "/docker-entrypoint.…" 3 seconds ago Up 2 seconds 80/tcp demo
# Pull and run nginx detached
docker run -d --name demo nginx:alpine

# Confirm it is running
docker ps

# Stop the container
docker stop demo

# Remove it
docker rm demo

# Confirm it is gone
docker ps -a
Which state does a container enter immediately after 'docker stop'?
What is the difference between an image and a container?
After 'docker stop', can you start the container again?