A container can have an IP address without being reachable from your physical network. Docker assigns that address on a virtual network it manages. Containers connected to the same Docker network can communicate, while outside computers cannot connect directly to a container’s virtual IP address. section 2.4 section 4.2
To make a containerized website reachable from your computer, publish a port. For example, `docker container run --detach --publish 8088:80 diamol/ch02-hello-diamol-web:2e` sends traffic arriving at the computer on port 8088 to port 80 in the container. Visit `http://localhost:8088` to check the result. Publishing a port exposes a route into the container; it does not put the container’s virtual IP address on your physical network. section 2.4
For an application with several containers:
- Create a network with `docker network create nat`. If `nat` already exists, the resulting error can be ignored. section 4.2
- Connect a container when starting it: `docker container run --name iotd -d -p 800:80 --network nat image-of-the-day`. Containers on that network can reach one another by container name; the published port separately makes this API reachable at `http://localhost:800/image`. section 4.2
- For a repeatable setup, declare services and networks in a Docker Compose file rather than retyping each container’s run options. section 7.1
Listing 7.1 A Docker Compose file to run the to-do app
services:
todo-web:
image: diamol/ch06-todo-list:2e
ports:
- "8020:80"
networks:
- app-net
networks:
app-net:
name: nat
external: true
The Compose example connects `todo-web` to `app-net`, which refers to an existing Docker network named `nat`; its `ports` entry handles host access separately. section 7.1
Separate application environments can use isolated Docker networks and unique published ports, allowing development and test versions to run on one server. A Docker virtual network does not join multiple physical machines; spreading containers across servers requires another platform, such as Kubernetes or a cloud service. section 10.5 section 1.3



