Hello dev.to community! π
Yesterday, I explored Docker Basics β the foundation of containerization. Today, Iβm diving into Networking & Volumes in Docker β two essential concepts that bring containers closer to real-world use cases. π³
πΉ Why Networking & Volumes Matter
Networking β lets containers communicate with each other and the outside world.
Volumes β ensure data persists even if containers are removed.
In DevOps, both are crucial for building reliable, production-ready systems.
π§ Core Concepts Iβm Learning
π Docker Networking
Bridge network (default): containers get private IPs and can talk to each other.
Host network: container shares hostβs network.
Overlay network: connects containers across multiple hosts (used in Swarm/K8s).
π§ Example:
Create a custom bridge network
docker network create mynet
Run two containers in the same network
docker run -d --name web --network mynet nginx
docker run -it --network mynet alpine ping web
πΎ Docker Volumes
Volumes store data outside container lifecycle.
Great for databases, logs, and config files.
Types: named volumes, host mounts, anonymous volumes.
π§ Example:
Create a volume
docker volume create mydata
Run MySQL with volume
docker run -d -v mydata:/var/lib/mysql mysql
π οΈ Mini Use Cases in DevOps
Run a database container with volumes to persist data.
Connect backend & frontend containers via networks.
Share config files securely across multiple services.
β‘ Pro Tips
Use named volumes instead of host paths for portability.
Inspect networks with:
docker network ls
docker network inspect mynet
Clean up unused volumes & networks:
docker volume prune
docker network prune
π§ͺ Hands-on Mini-Lab (Try this!)
1οΈβ£ Create a network:
docker network create devnet
2οΈβ£ Run Nginx & Redis in the same network:
docker run -d --name mynginx --network devnet nginx
docker run -d --name myredis --network devnet redis
3οΈβ£ Verify connectivity:
docker exec -it mynginx ping myredis
π― Containers are now talking to each other inside devnet! π
π― Key Takeaway
Networking connects containers like a mini-internet, while volumes ensure data survives beyond container restarts. Together, they make Docker production-grade.
π Tomorrow (Day 9)
Iβll dive into Dockerfiles & Image Building β automating app packaging for CI/CD pipelines.
π #Docker #Containers #DevOps #CICD #DevOpsJourney #CloudNative #SRE #Automation #OpenSource
Top comments (0)