docker network configuration

Views:
 
Category: Education
     
 

Presentation Description

Docker network configuration concept is very important for every docker engineer. Because without complete knowledge of docker network we cannot manage containers properly. https://linuxdady.com/docker-network-configuration/

Comments

Presentation Transcript

slide 1:

LinuxDady.Com Docker network configuration step by step for beginners For more information visit https://linuxdady.com

slide 2:

Understand docker network configuration concept Docker network configuration concept is very important for every docker engineer. Because without complete knowledge of docker network we cannot manage containers properly. So in this tutorial we are going to learn how to configure docker network and what are the type of docker network Docker network configuration Before moving forward first we have to take a look of theoretical part of docker network type. Basically docker using two type of network: – ▪ Bridge network ▪ Host network Bridge Network If you want to separate IP over every container or you want to run multiple containers using the same port on docker host then there is no option except bridge network means with help of bridge network we can isolate our container with different different IP address. All these containers connected to physical network card NIC via bridge network. We have to do only port forwarding to pass traffic from docker host to container via bridge network. For better understanding go through diagram. Host Network

slide 3:

Let’s take a scenario to understand host network suppose you want to run a webserver container via using host network. So when container will launch it will use IP address and port number of base machines means our webserver will run into container but using base host IP and port number. So remember one thing your 80 port is reserved for webserver in future we cannot launch more container of webserver because they will use port 80 but port 80 is already in use. So using host network is not best approach but it’s depends on requirement. Click Read: – How to mount external volume with container Click Read: – How to create docker image manually and from dockerfile Now we are going to launch a container and check which one IP address is container getting from default pool. 1 docker run -it --name con1 centos:latest

slide 4:

We will find that it is providing IP address from its default pool. After installing net-tools package run ifconfig command to check IP address. 1 Ifconfig Docker network configuration list we can check by below command. This command will show all available docker network type. docker network ls In above figure we have checked here bridge and host default network are showing . Now let’s add new bridge adapter manually. Prod is name of bridge

slide 5:

network that we are going to add and 192.168.10.0/24 is my subnet. In your case change name and subnet accordingly. docker network create --subnet 192.168.10.0/24 --driver bridge prod docker network ls We have successfully added bridge network with name prod of subnet rang 192.168.10.0/24. Now we will launch a container into this subnet. New upcoming container will use IP address from this subnet. docker run -it --name con1 --network prod centos:latest yum install net-tools -y ifconfig Execute ifconfig command and check which one IP is showing. IP address should be from new subnet like 192.168.10.2. It is providing IP address that is free into bridge pool. We are going to set manually IP address at our upcoming container. docker run -it --name con2 --ip 192.168.10.99 --network prod centos:latest ifconfig eth0

slide 6:

Put a container more than one network means we can attach multiple adapter with a container. 1 docker network connect bridge con2 Check how many adapters are attached with con2. docker inspect con2 |grep "IPAddress" We can attach and detach network of container on the fly. To change IP address from Ethernet configuration file manually is not best practice. docker network disconnect bridge con2 or if you want to delete prod bridge network permanently then execute below command. docker network rm prod docker network ls

slide 7:

Host Network As discussed already docker network is used when we need to run single service on single port means it will use network of base machine. Let’s have a look 1 docker run -it --name con1 --network host centos:latest Conclusion In this tutorial we have covered docker networking part which is very important of every docker engineers. Because without docker network configuration you cannot manage container properly. So still if anyone have query regarding docker network write in comment box. I will try my best to resolve them. Interview question from docker network configuration 1. When we launch a container which one IP is assigned by default statics or dynamic 2. Can we change container IP on the fly means in ruining state

slide 8:

3. Can we attach a container more than one bridge network 4. What is the difference between host network and bridge network 5. When I want to run multiple container of same service so which one will be the best approach for networking from Bridge or host network

authorStream Live Help