Running containers
Run a web server
Section titled βRun a web serverβdocker run -d --name web -p 8080:80 nginx:1.27| Flag | Meaning |
|---|---|
-d |
Detached β run in the background |
--name web |
Give the container a name instead of a random one |
-p 8080:80 |
Publish container port 80 on host port 8080 (host:container) |
nginx:1.27 |
The image and its tag. Always pin a tag rather than relying on latest |
Open http://localhost:8080 and youβll see the nginx welcome page.
Look around
Section titled βLook aroundβdocker ps # running containersdocker logs -f web # follow its output (Ctrl+C to stop following)docker exec -it web sh # open a shell inside itdocker inspect web # everything Docker knows about it, as JSONClean up
Section titled βClean upβdocker stop webdocker ps -a # the stopped container still existsdocker rm web