Lesson 2 · Unit 01
Running containers
run, ps, logs, exec, stop, rm, and where written files go
What you practise
docker runwith ports, environment and a name, detached mode,ps,logs,exec, stop and remove- What happens to files written inside
Try a question from this lesson
Pick one
A web server listens on port 80 inside a container started with: docker run -d nginx. On the host, localhost:80 refuses the connection. Why?
Hint
Which namespace does a listening port belong to?
Correct answer
Port 80 is in the container's own network; nothing published it
Why
The container has its own network namespace, so its port 80 is not the host's port 80. To reach it from the host you publish it: -p HOST:CONTAINER.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Reading docker run
Flags come first, the image last.
-d runs in the background and prints the container's ID. --name gives it a name you can use in later commands. -p 8080:80 sends the host's port 8080 to port 80 in the container. -e sets an environment variable inside.
docker run -d --name web \
-p 8080:80 -e MODE=prod nginxConcept
Where written files go
Each container gets a thin writable layer on top of its image. Every file it creates or changes lives there.
docker stop keeps the layer. docker rm deletes it. A new container from the same image starts from the image's files again, with an empty layer of its own.
10 more exercises in the app
- 1× fill the blanks
- 1× type the answer
- 4× multiple choice
- 1× match the pairs
- 2× true or false
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.