teluzia.Cloud Engineer · Day 102
CHAPTER 15 · DOCKER AND CONTAINERS

Networking and volumes

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Networks connect container processes; volumes are labeled storage lockers that can outlive the processes using them. Host publication maps a host interface and port to a container port. Containers on a user-defined bridge network can resolve each other by name. localhost inside a container refers to that container, not another service or automatically the host. Exposing metadata is not the same as publishing a host port. The container writable layer belongs to that container’s lifecycle. A named volume is separately managed storage that can survive container removal. Choose mount paths deliberately and understand whether initialization or application writes land on the volume or an ephemeral layer.

Think of it this way

Networks connect container processes; volumes are labeled storage lockers that can outlive the processes using them.

TOPIC 01 / 03Step by step

Published ports and container networks

Host publication maps a host interface and port to a container port. Containers on a user-defined bridge network can resolve each other by name. localhost inside a container refers to that container, not another service or automatically the host. Exposing metadata is not the same as publishing a host port. For example, a frontend calls http://api:8080 on the shared network, while a host browser uses a published localhost port.

WORKED EXAMPLE
A frontend calls http://api:8080 on the shared network, while a host browser uses a published localhost port.

A host browser connects to localhost:8200, which Docker forwards to a container's port 80. Inside that container, localhost still identifies the container's own network namespace, not the host browser or a second container. Two containers on a suitable user-defined network can instead communicate through their configured names and container ports.

A published port maps host reachability to a container port. A bridge network connects participating containers. DNS discovery translates service or container names into reachable addresses within its supported scope. EXPOSE documents an intended port but does not itself publish it to the host. Diagnose source location, destination address, listening interface, and port mapping separately. A server listening only on container-local loopback may not accept forwarded traffic through its network interface. Publishing on every host interface can expose a development service to other machines, so use explicit localhost bindings for local beginner exercises.

Why this matters

A frontend calls http://api:8080 on the shared network, while a host browser uses a published localhost port.

A common trap

Do not overlook this operational distinction: Exposing metadata is not the same as publishing a host port.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Published ports and container networks

Host publication maps a host interface and port to a container port. Containers on a user-defined bridge network can resolve each other by name. localhost inside a container refers to that container, not another service or automatically the host. Exposing metadata is not the same as publishing a host port. For example, a frontend calls http://api:8080 on the shared network, while a host browser uses a published localhost port.

WORKED EXAMPLE
A frontend calls http://api:8080 on the shared network, while a host browser uses a published localhost port.

A host browser connects to localhost:8200, which Docker forwards to a container's port 80. Inside that container, localhost still identifies the container's own network namespace, not the host browser or a second container. Two containers on a suitable user-defined network can instead communicate through their configured names and container ports.

A published port maps host reachability to a container port. A bridge network connects participating containers. DNS discovery translates service or container names into reachable addresses within its supported scope. EXPOSE documents an intended port but does not itself publish it to the host. Diagnose source location, destination address, listening interface, and port mapping separately. A server listening only on container-local loopback may not accept forwarded traffic through its network interface. Publishing on every host interface can expose a development service to other machines, so use explicit localhost bindings for local beginner exercises.

Why this matters

A frontend calls http://api:8080 on the shared network, while a host browser uses a published localhost port.

A common trap

Do not overlook this operational distinction: Exposing metadata is not the same as publishing a host port.

Named volumes and writable layers

The container writable layer belongs to that container’s lifecycle. A named volume is separately managed storage that can survive container removal. Choose mount paths deliberately and understand whether initialization or application writes land on the volume or an ephemeral layer. For example, a database stores files at its documented data directory mounted from a named volume rather than an arbitrary unused path.

WORKED EXAMPLE
A database stores files at its documented data directory mounted from a named volume rather than an arbitrary unused path.

A container writes a report to its ordinary writable layer, then is removed and recreated. The new container does not inherit that report. A named volume mounted at the application's report directory changes the persistence boundary: another container can mount the same retained volume and read the report after the first container disappears.

The writable layer belongs to a container instance. A named volume is separately managed storage. A mount destination is the path where that storage appears inside the container. Mounting at the wrong path can leave the application writing ephemeral data elsewhere. Some image paths have initialization behavior, so read the application's documented data location rather than guess. Volume persistence is not backup or replication; accidental deletion or corrupt writes can still destroy useful data. Record volume ownership and retention before cleanup, and never assume container removal automatically removes or safely preserves every storage object.

Why this matters

A database stores files at its documented data directory mounted from a named volume rather than an arbitrary unused path.

A common trap

Do not overlook this operational distinction: Choose mount paths deliberately and understand whether initialization or application writes land on the volume or an ephemeral layer.

Bind mounts and ownership

Bind mounts expose a specific host path inside a container. They are useful for development but can modify host files and encounter platform or ownership differences. Read-only mounts reduce unwanted writes. Do not mount sensitive host directories simply to avoid copying small practice inputs. For example, mount a practice config file read-only while a separate named volume holds writable application data.

WORKED EXAMPLE
Mount a practice config file read-only while a separate named volume holds writable application data.

A developer bind-mounts a practice directory into /app. The mount can obscure files originally present at that image path and makes selected host files visible to the process. If the container writes there, it may change the host directory. Permission mismatches can make writes fail even though image-building permissions seemed correct.

A bind mount exposes a particular host path. Read-only mounting rejects writes through that mount. Ownership and permissions determine which process identities can access files. Bind mounts suit interactive development, while named volumes often avoid coupling runtime data to a particular host path. Platform differences and remote daemons can change which host filesystem the path refers to. Do not mount a whole home directory to fix a missing input file. Expose the smallest necessary path, use read-only access for configuration, and inspect the actual mount when debugging so hidden image content is not confused with deleted data.

Why this matters

Mount a practice config file read-only while a separate named volume holds writable application data.

A common trap

Do not overlook this operational distinction: Do not mount sensitive host directories simply to avoid copying small practice inputs.

KEEP THESE WITH YOU

Today’s takeaways

Published ports and container networks: Host publication maps a host interface and port to a container port. Containers on a user-defined bridge network can resolve each other by name. localhost inside a container refers to that container, not another service or automatically the host. Exposing metadata is not the same as publishing a host port.

Named volumes and writable layers: The container writable layer belongs to that container’s lifecycle. A named volume is separately managed storage that can survive container removal. Choose mount paths deliberately and understand whether initialization or application writes land on the volume or an ephemeral layer.

Bind mounts and ownership: Bind mounts expose a specific host path inside a container. They are useful for development but can modify host files and encounter platform or ownership differences. Read-only mounts reduce unwanted writes. Do not mount sensitive host directories simply to avoid copying small practice inputs.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed