Running Containers
5 min read Quiz at the end
Run, stop, restart, and remove containers — master the essential docker run flags.
Running Containers
docker run nginx
docker run -d nginx # detached/background
docker run -d -p 8080:80 nginx # port mapping host:container
docker run -d --name webserver nginx
docker run -it ubuntu bash # interactive terminal
docker run --rm alpine echo hi # auto-remove on exit
docker ps
docker ps -a
docker stop webserver
docker start webserver
docker rm webserver
docker rm -f webserver # force remove
docker logs -f webserver
docker exec -it webserver bash
Topic Quiz · 3 questions
Test your understanding before moving on
1. What does the -d flag in docker run do?
💡 The -d flag runs the container in detached mode (background) and prints the container ID.
2. Which flag maps host port 8080 to container port 80?
💡 The -p host:container flag publishes a container port to the host.
3. Which command follows container logs in real time?
💡 The -f (follow) flag streams new log output as it is written.