☑️Day 26: Exploring Docker Registry and Networking🚀
🔹Table of Contents :
Introduction
Beginner-Level Docker Networking Commands
Hands-On Practice
Task 1: Container Communication on the Same Network
Task 2: Custom Subnet and Host Communication
Key Takeaways
✅1. Introduction
Docker Registry:
A centralized place to store and manage Docker images. It's like a repository for all your containerized applications.
Public Registry: Docker Hub is a common public registry.
Private Registry: Companies often use private registries for internal image storage.
Docker Networking:
Bridge Network: The default network mode. Containers on the same bridge can communicate with each other.
Host Network: The container shares the host’s network stack directly.
Overlay Network: Designed for multi-host networks, often used in Docker Swarm or Kubernetes clusters.
Custom Networks: You can create your own networks with specific subnets, IP ranges, and more.
✅2. Beginner-Level Commands:
List Available Networks:
docker network ls
Create a New Network:
docker network create --subnet 172.10.0.0/24 mynet123
Run a Container in a Custom Network:
docker container run -itd --net mynet123 --ip 172.10.0.20 --hostname myubuntu ubuntu:latest
Inspect Network Details:
docker network inspect bridge
Connect an Existing Container to a Network:
docker network connect mynet123 container_name
Check Container IP Address:
docker inspect container_name | grep -i ipaddress
Ping Between Containers:
docker exec -it container_name /bin/bash ping <container_ip_address>
✅3. Hands-On Tasks:
Task 1: Container Communication on the Same Network
Create 3 containers—2 on the same network and 1 on a separate network. Test connectivity between them using ping
.
List Existing Networks:
docker network ls
Create a New Network (for the 2 containers):
docker network create mynet123
Run Two Containers on the Same Network:
docker container run -itd --net mynet123 --name container1 ubuntu:latest docker container run -itd --net mynet123 --name container2 ubuntu:latest
Run a Third Container on the Default Bridge Network:
docker container run -itd --name container3 ubuntu:latest
Check Container IP Addresses:
docker inspect container1 | grep -i "IPAddress" docker inspect container2 | grep -i "IPAddress" docker inspect container3 | grep -i "IPAddress"
Ping from
container1
tocontainer2
:- First, enter the
container1
shell:
- First, enter the
docker exec -it container1 /bin/bash
Now, ping container2
:
ping <container2_ip_address>
Try Pinging
container3
fromcontainer1
(this should fail, as they’re on different networks):ping <container3_ip_address>
Task 2: Create a Custom Subnet & Communicate Between Containers
Create a custom subnet, run a container on it, and verify connectivity with a custom IP address.
Create a Custom Subnet:
docker network create --subnet 172.10.0.0/24 mynet456
Run a Container with a Custom IP Address:
docker container run -itd --net mynet456 --ip 172.10.0.20 --hostname myubuntu --name custom-container ubuntu:latest
Check the
/etc/hosts
File Inside the Container (to verify hostname):docker exec -it custom-container /bin/bash cat /etc/hosts
Ping the Container to Check Connectivity:
From your local machine:
ping 172.10.0.20
✅4. Key Takeaways:
Docker networking provides flexibility in how containers communicate.
With Docker Registry, images can be shared and reused across environments.
Custom networks and subnets offer control over how containers interact with one another, making them ideal for complex environments.
🚀Thanks for joining me on Day 26! Let’s keep learning and growing together!
Happy Learning! 😊
#90DaysOfDevOps
#Docker #DevOpsJourney #ContinuousLearning #Day26 #DockerNetwork #Networking #DockerRegistry #ShubhamLonde
Subscribe to my newsletter
Read articles from Kedar Pattanshetti directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by