Running Containers in the Background
An image is only the template — life begins when you run a container from it. This time we focus on one idea: how to start a long-running container (like a web server) that runs in the background without holding your terminal, and how to look at it while it runs. We learn docker run -d (run in the b
Running in the background is like switching on a fridge and walking away: it keeps working on its own without you standing in front of it, and any time you can open the door and peek inside to see what is going on — that is exactly docker logs.
- detached mode (-d)
- Running a container in the background with docker run -d, so the terminal is freed immediately instead of being held by the container's output.
- port publish (-p)
- Mapping a host port to a port inside the container with -p host:container, so traffic from outside reaches the service running in the container. (A port is a numbered 'door' through which you reach a service — we met it in the 'How Programs Run' primer.)
- docker logs
- A command that shows the stdout and stderr the container wrote. When the container runs in the background, this is your first window into what it 'said'. (stdout/stderr are the normal-output and error channels — we met them in the primer.)