HomeLinux Administration

Docker Container | Customize the docker Network

Docker Container | Customize the docker Network
Like Tweet Pin it Share Share Email
Personal Development Category (English)728x90

In the previous article, you have learned about basics of Docker Container and the installation on CentOS7.  After installing the Docker, it is important to know advanced methods like Customize the Docker Network and required modifications for your Docker Containers. Here I have provided few scenarios where you can use the custom network for Docker Container.  Follow the below step by step guide for modifying the necessary changes on host level and also check the Youtube Video for clear understanding.

Why use custom Network Subnet for Docker Networking?

Docker container makes use of default subnet “172.17.0.0/16” for Networking. There may be many scenarios where we can’t use the default network due to some restrictions or in case subnet already used in the network.

Lab Tasks

In this quick session, we will change the network from default subnet “172.17.0.0/16” to “10.10.10.10/24“. The bridge interface remains to docker0  i.e. default.

Also, Check out the Docker Network Video for more details:

Docker Network

Configure the Custom Network: before doing changes for Docker Container, make sure stop the Docker service, then proceed further.

Stop the Docker Service

# systemctl stop docker.service

Bring down the Docker bridge docker0

# ip link set dev docker0 down

Verify if IP forwarding is enabled, if not enable it in sysctl.conf

# sysctl net.ipv4.conf.all.forwarding

Update new subnet in the /etc/sysconfig/docker-network add the following to DOCKER_NETWORK_OPTIONS-:

“–bip=YOUR.CIDR.ADDRESS/24”

Example

DOCKER_NETWORK_OPTIONS=”–bip=10.10.10.10/24″

Remove default subnet’s MASQUERADE rules from the POSTROUTING chain in network iptables/firewalld service.

# iptables -t nat -F POSTROUTING

# iptables -F DOCKER

Start Docker service

# systemctl start docker.service

Verify that the MASQUERADE rule has new subnet added to the POSTROUTING chain.

# iptables -t nat -L n

Validation

Check the new subnet is on the bridge now.

# docker network inspect bridge

Check IP Address of the Container

# docker inspect -f ‘{{ .NetworkSettings.IPAddress }}’ [Container ID]

Run a docker container and check container have

# docker run -it [Container Name] /bin/bash

Conclusion: I hope this article gave you the basic knowledge of customizing the Docker Networking and how can you use own network settings for your Docker Containers. If you have any queries on this, you can comment on below. We are happy to help you here.

Comments (3)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.