Skip to content

Running containers

Terminal window
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.

Terminal window
docker ps # running containers
docker logs -f web # follow its output (Ctrl+C to stop following)
docker exec -it web sh # open a shell inside it
docker inspect web # everything Docker knows about it, as JSON
Terminal window
docker stop web
docker ps -a # the stopped container still exists
docker rm web

Check your understanding

1. Which flag publishes container port 80 on host port 8080?
2. What does `docker ps -a` show that `docker ps` doesn't?