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 → removedThe run flags you will use constantly:
-druns it detached, in the background.--name notesgives it a name, so you do not have to copy random IDs.-p 8080:5000publishes a port: host port first, container port second. Your browser openslocalhost:8080, and Docker forwards it to port 5000 inside the container.--rmremoves 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.