☑️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.

  1. List Existing Networks:

     docker network ls
    
  2. Create a New Network (for the 2 containers):

     docker network create mynet123
    
  3. 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
    
  4. Run a Third Container on the Default Bridge Network:

     docker container run -itd --name container3 ubuntu:latest
    
  5. Check Container IP Addresses:

     docker inspect container1 | grep -i "IPAddress"
     docker inspect container2 | grep -i "IPAddress"
     docker inspect container3 | grep -i "IPAddress"
    
  6. Ping from container1 to container2:

    • First, enter the container1 shell:
    docker exec -it container1 /bin/bash

Now, ping container2:

    ping <container2_ip_address>
  1. Try Pinging container3 from container1 (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.

  1. Create a Custom Subnet:

     docker network create --subnet 172.10.0.0/24 mynet456
    
  2. 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
    
  3. Check the /etc/hosts File Inside the Container (to verify hostname):

     docker exec -it custom-container /bin/bash
     cat /etc/hosts
    
  4. 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

💡
Follow for more updates on LinkedIn , Github and Twitter(X)
0
Subscribe to my newsletter

Read articles from Kedar Pattanshetti directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kedar Pattanshetti
Kedar Pattanshetti