Running & Listing Containers
docker run - the Big One
$ docker run -d --name web -p 8080:80 nginx:alpine
Reading left to right:
| Flag | Meaning |
|---|---|
-d | detached - run in the background |
--name web | a human name (otherwise Docker invents one like angry_swanson) |
-p 8080:80 | publish port: host 8080 → container 80 |
nginx:alpine | the image (always last, before any command) |
Tip: The -p HOST:CONTAINER order trips everyone up at least once. The left number is the port you browse to; the right one is what the app listens on inside.
See what's running (-a includes stopped ones - crucial when things crash):
$ docker ps
CONTAINER ID IMAGE STATUS PORTS NAMES
3f2a91c04d11 nginx:alpine Up 2 minutes 0.0.0.0:8080->80/tcp web
$ docker ps -a # also shows Exited / Created containers
Note:docker run=create+start. A container that failed to start still exists -docker ps -ais the first debugging command you should reach for.