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
| Command | What it does |
|---|---|
docker ps | List running containers |
docker ps -a | Include stopped containers |
docker run -d --name web -p 8080:80 nginx:1.27 | Start detached with port mapping |
docker stop <name> && docker rm <name> | Stop then remove |
docker container prune | Remove 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.
常见问题
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
Docker Install and Setup
Verify the Docker engine, configure context, and check versions.
Docker Images
Pull, list, tag, inspect, and remove images confidently.
Docker Run Options
The flags that matter: detach, ports, env, volumes, limits.
Docker Exec and Logs
Get a shell inside containers and read their logs effectively.