Docker Containers

Run, list, stop, and clean up containers in daily work.

  • docker ps
  • docker run
  • docker stop
  • docker rm
  • container prune

Docker Containers

Run, list, stop, and clean up containers in daily work.

Commands

CommandWhat it does
docker psList running containers
docker ps -aInclude stopped containers
docker run -d --name web -p 8080:80 nginx:1.27Start detached with port mapping
docker stop <name> && docker rm <name>Stop then remove
docker container pruneRemove all stopped containers

Example

docker run -d --name web -p 8080:80 nginx:1.27
docker ps
docker stop web && docker rm web

FAQ

Why did my container exit immediately?

The main process ended (e.g. bash without -it). Check docker ps -a plus docker logs to see why.

How do I auto-restart containers?

Add --restart unless-stopped (or an orchestrator); plain docker run never restarts on its own.

SSS

Why did my container exit immediately?
The main process ended (e.g. bash without -it). Check docker ps -a plus docker logs to see why.
How do I auto-restart containers?
Add --restart unless-stopped (or an orchestrator); plain docker run never restarts on its own.

Docker