Skip to the workspace
Pebellslearn by building
Basics of Docker  ›  Lesson

Running and Managing Containers

Basics of Docker 14 mindocker run creates and starts a container, stop halts it while keeping it, start revives it, and rm deletes it, with ps, logs and exec to look inside along the way.

docker / Running and Managing Containers

Explore each scene at your own pace.

01 · The rule

The rule

Running and Managing Containers

You have the quicknotes image. Now you want it running in the background, reachable in your browser, and you want to read its logs, peek inside, stop it and clean it up. Six or seven commands cover nearly all of that, and they all follow one lifecycle.

The rule

run = create + start; stop keeps it; rm deletes it.

A container moves through a few states: created → running → exited → removed. The main commands move it between them:

docker run -d --name notes -p 8080:5000 quicknotes:1.0
docker ps                 # running containers
docker logs notes         # what the app printed
docker exec -it notes sh  # open a shell inside
docker stop notes         # running → exited
docker ps -a              # all containers, including exited
docker start notes        # exited → running again
docker rm notes           # exited → removed

The run flags you will use constantly:

  • -d runs it detached, in the background.
  • --name notes gives it a name, so you do not have to copy random IDs.
  • -p 8080:5000 publishes a port: host port first, container port second. Your browser opens localhost:8080, and Docker forwards it to port 5000 inside the container.
  • --rm removes the container automatically when it exits; handy for one-off runs.

docker stop sends the main process a polite stop signal, waits (10 seconds by default), then forces it. The container is exited, not gone: its writable layer and settings remain, which is why start can bring it back. Only rm deletes it, and rm refuses a running container unless you stop it first or add -f.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.