Networks and localhost
Networks and localhost — Docker Compose for AI services. Host and container ports; Use service names rather than IPs; Understand the isolation boundary. Practical assignment: Practice: Networks and localhost.
Demo edition. The materials are undergoing editorial review.
Topics covered
- Host and container ports
- Use service names rather than IPs
- Understand the isolation boundary
Host and container ports
In 127.0.0.1:11434:11434, the first port belongs to the host and the second to the container. Changing the host port does not change the service address inside Compose. Access the VPS through an SSH tunnel rather than exposing the model to the internet. Use an available laptop port such as 18080 and target 127.0.0.1:11434 on the VPS. If the local port is occupied, change only 18080. Transport protection does not replace permission to use the model or its data.
ssh -N -L 18080:127.0.0.1:11434 operator@lab.example
# In a second client terminal, while the tunnel remains open:
curl --fail --max-time 5 http://127.0.0.1:18080/api/tags
Use service names rather than IPs
Another container on the same Compose network calls http://model:11434. Its localhost refers to itself, not the VPS or a neighboring container. Recreating a service may change its IP while preserving its service name. Do not hardcode the dynamic address in a client. Work through three destinations: host uses 127.0.0.1:11434, tunneled laptop uses 127.0.0.1:18080, and container client uses model:11434. When the destination is correct but connection fails, inspect shared network membership and readiness before changing ports.
Understand the isolation boundary
Omitting ports does not prevent containers on the same network from contacting a service. Separate networks restrict neighbors; an internal network also removes the normal external route. A container attached to two networks may still reach the internet through the other one. Start with ordinary bridge networking and a loopback mapping, avoiding host mode. Check Engine version: official documentation warns about localhost publishing before 28.0.0 on shared L2 networks. Isolation conclusions require the real topology, not YAML alone.
Practical assignment
Practice: Networks and localhost
Continue to learning