What You'll Learn
Beginner
- How containers get network access
- How containers communicate with each other
- Port mapping vs direct container-to-container
Docker network types and a custom bridge network with DNS
Terminalbash
# Create a custom network (has DNS!)
docker network create my-net
# Containers resolve each other by name
docker run -d --name web --network my-net nginx
docker run -d --name api --network my-net node:18
# api can reach web by name:
docker exec api curl -s http://webPractical Exercise
Create a custom network
Run two containers on it
Test DNS resolution with
curl http://webKey Takeaways
- Containers get their own IP on the bridge network.
-p host:containerpublishes ports.- Custom networks have built-in DNS — containers resolve by name.
- This is the foundation for Docker Compose.
Comments
Comments
Post a Comment