🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Out of the box, Docker offers a few default networks, such as bridge, none, and host. However, there are scenarios where creating a custom network becomes essential, like when building multi-tier applications. In this guide, we will learn how to create a custom Docker network.
Why a Custom Network?
Enhances DNS Resolution: Containers can easily communicate via their names.
Offers Network Segmentation: Different apps can be isolated in different networks.
Allows Network Customization: Custom IP address ranges, gateways, and subnets can be defined.
Step-by-Step Creation of a Docker Network
1. Verify Existing Networks:
Before creating a new network, it's advisable to check the current networks:
docker network ls2. Creating the Custom Network:
The general syntax is:
docker network create [OPTIONS] NETWORK_NAMEFor instance, to create a bridge network named my_custom_network:
docker network create --driver bridge my_custom_networkdocker volume create myvolume$ docker volume create
d7fb659f9b2f6c6fd7b2c796a47441fa77c8580a080e50fb0b1582c8f602ae2f3. Specifying Subnets and Gateways (Advanced):
For more granular control, you can specify the subnet, the IP range, and the gateway:
docker network create --driver bridge --subnet 192.168.0.0/16 --ip-range 192.168.1.0/24 --gateway 192.168.1.1 my_advanced_network4. Connecting Containers to the Network:
Once created, you can either start a new container in this network or connect an existing container. Starting a new container in the network:
docker run --network=my_custom_network -d nginxConnecting an existing container:
docker network connect my_custom_network container_name_or_id5. Inspecting the Network:
Let's see how to inspect the existing network:
docker network inspect my_custom_networkThe docker network inspect command provides detailed information about a specific Docker network.
If my_custom_network doesn't exist, the command will return an error saying the network is not found.
6. Clean Up: Removing the Network
Should you no longer require the network, you can easily remove it. Ensure no active containers are connected to it:
docker network rm my_custom_networkConclusion
In this guide, we have learned how to create volume, remove volume, list volumes, and inspect volume.
Related Networking Guides
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment