Day-to-day work with containers is mostly these commands.
Once containers are running you need to see and control them.
docker pslists running containers;docker ps -aincludes stopped ones. Each has an ID (any unique prefix works) and a name.docker logs apiprints what the main process wrote to stdout and stderr.-ffollows,--tail 100limits,--since 10mfilters by time. This is why containerized apps should log to stdout rather than to files.docker exec -it api shruns an additional process in a running container, here a shell, so you can poke around. Usebashif the image has it.execonly works while the container is running.docker stop apisendsSIGTERMto the main process, waits (10 seconds by default,-tto change), then sendsSIGKILL. Apps should handle SIGTERM to shut down gracefully.docker kill apisendsSIGKILLimmediately.docker start api/docker restart apistart a stopped container again, keeping its writable layer.docker rm apideletes a stopped container;docker rm -f apistops and deletes it.docker inspect apidumps full JSON details: state, exit code, IP address, mounts, env. Use--formatto pick fields.docker statsshows live CPU and memory per container.
Containers that stop keep existing until removed, so docker ps -a grows over time. docker container prune removes all stopped containers in one go.
Example
docker run -d --name api -p 8000:8000 python:3.13 python -m http.server
docker ps # running containers
docker logs -f --tail 20 api # follow output (Ctrl+C stops following)
docker exec -it api bash # shell inside; exit to leave
docker exec api ls / # one-off command
docker inspect api --format '{{.State.Status}} {{.NetworkSettings.IPAddress}}'
docker stop api # SIGTERM, then SIGKILL after 10 s
docker ps -a --filter name=api # Exited (...)
docker start api && docker restart api
docker rm -f api
docker container prune # remove all stopped containersRemember
- ps lists; logs shows stdout/stderr; exec runs extra processes inside
- stop = SIGTERM, then SIGKILL after a grace period
- Stopped containers persist until docker rm or prune
- inspect --format pulls any detail out of the JSON
Watch out for
- Expecting docker logs to show files the app writes to /var/log — it only captures stdout and stderr.