Container lifecycle

A container goes through created, running, exited and removed. docker stop, start and restart move it between these states; only docker rm deletes it, with its writable layer.

How it works

docker run is create plus start. docker stop sends SIGTERM to the main process, waits 10 seconds, then sends SIGKILL. A stopped container keeps its files, configuration and logs until it is removed: docker ps hides it, docker ps -a shows it.

What breaks

A container's configuration (ports, environment, volumes, limits) is fixed when it is created. Restarting it does not pick up new options: remove it and run it again. A stopped container also keeps its name, hence the error "Conflict. The container name is already in use".

In a terminal

docker run -d --name web nginx:1.27
docker stop web
docker ps -a
docker start web
docker rm -f web

See it break, then fix it

Write the Dockerfile or the compose file, type the docker commands, and watch a simulated server run them through reboots, upgrades and traffic. Free to start.