Docker Networking

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] if you are seeing this video that means you had already done with basic installation of docker and you know how to run the containers the basic idea behind the container and in the previous video if you remember we had done with the how how can you have your image is pulled and pushed using the docker hub so this particular video as I have told you we will be focusing on how the token network works that's very interesting so let's move ahead and shift the gears so remember one thing guys when every your darker engine starts whenever your docker daemon starts it by defaults create a virtual Ethernet bridge and they call it dr. zero and there is a very simple command docker network list by which you can see that so if I open my machine here the trusted machine which we used and I give her darker network list you will see that I have a bridge network already there connected to it right and the scope is local that means it is accessible from within the machine and this is the network ID so whenever you run any instance not the instance sorry hangover of cloud wherever you run any container so by default all the containers will be connected to this bridge I'll be showing this and you can confirm this by giving the command BR serial so you can very clearly see there the bridge name is taka 0 and there is no interface in it because I don't have any container running right now it's blank so as soon as I run a container the container will by default will be connected to the bridge 0 so let's move further so this is what you need to understand first secondly and you can also reconfirm it by giving ifconfig command or IPS command on your host machine so if I move in here and I give I pas command you can very clearly see this is a darker zero interface with the IP address of 170 2.17 dot zero dot one which is the by default address for the docker 0 network that default network so understand this so whenever you create a container it will by default be connected in this bridge and we'll be getting the IP from the same range so the first container which I will run will get the IP of 172 1217 dot 0 dot 2 right and this I will have the the interface ID the West interface will be appearing here I'll show it that so you should remember this so and interesting there is a very interesting command docker network inspect bridge or whatever the name of the network is to get more details about the IP address configurations and all the things you can do so I can give the command here talk Network inspect and the name so you can get the name by the LS this is the name copy this and to give the command docker Network inspect and paste it so here you go you get a lot of information or deep diving into the bridge network so the scope is local the driver is the bridge we will be focusing on the drivers but not right now and this is the configuration or the configuration so that means this network has this IP range and currently I don't have any containers running inside it so when whenever you run a container here you will find the container will appear here let's run it and check it out so this is what the slide shows you that I had done this command now what you do as I had already mentioned you there is no container running here so it's coming up to zero now let's run a container here and see what happens so if I give the command docker images I will be using the smallest image Alpine like you top car run I hope you still remember this right I'm not specifying any network so when I'm not specifying any network it's going to be by default inside the docker serum and the name is say I say one and I use Alpine latest and she'll that's it I'm running a container so if I give a I peek command here can see this container automatically gets the IP of 170 2.17 dot 0.2 I can reconfirm it I'll open another terminal make it bigger in size and better to use the same dimensions here or I'll use it here no problem so if I keep the command here see if I give the command be our CTL so remember you can see there of that interface automatically get connected so this is the virtual Ethernet interface or the LAN card or the n IC of that container and you can reconfirm it by giving the IPAs command see it is ending with b8b 1 so this is it 8p1 of that interface also appears right inside your and it is connected to the Dockers 0 bridge and if you give network doctor network list and I can give the same inspect command here just use your up arrow key some thousand times or hundred times whatever I can give dr. inspect Network and just give the ID or the name it doesn't matter so I keep it and here you see there is a container coming up here the name is the one the endpoint is this and this is the IP address allocated to that container so you can reconfirm all these things whatever the changes are happening on the host by these commands so first understand the basics now let's move on further so we had already done this this is the picture I really want you to focus on right this is my LAN card this is my host machine the physical box this is the actual LAN card it's zero and by default there is a docker bridge automatically created by the docker engine and every container that you run will have a vet interface connected to the dock or zero and then dr. zero will be connecting to the actual and I see the physical and I see so yes we can create our own customized network so in this case if you see there I'm creating I have a my bridge network there with the IP address of certain some different range and then I can have my connect some containers connected to this so we'll be doing all this stuff don't worry this is going to be a slightly longer class or the session right so just ignore this ID I don't need to update this we had already done this right so the first interface that we had learned and we had checked it the first container sorry so this is it so if I run another container here so if I give the command here docker PS that will be showing me one container one is running up here okay so if I run one more container here let's see I'll run the same docker run - - remove - IT - - name is - and alpine latest and then was ship right so one more container is coming up and the IP is three so that makes sense the first container will have the IP of two because the one is for the docker bridge and the second container will have the IP of three so that means I should be able to bring - to 170 2.17 dot zero dot - fair enough perfect and why it's very simple stuff because just go through that particular because the another container which I am running here the another container is also in this particular Network so they both are able to talk to each other this is having IP of three and this one will be having the IP of three and two right so this is how they are able to talk to each other fair enough and one more thing I wanted you to see here is that's good if I show you cat Etsy hosts that this is interesting you see here by default the Etsy host will have the IP address and the name this is the name of the container I'll show you I'll open another terminal for you and if I move in again and give dr. yes you will see the it's 1b 11 B this is 11 B so every host will automatically have AG uh this entry so that it should be able to get his name resolved and we can also give the host name by the way a while creating the container so if I do a exit here and I repeat the same command I show you the PS - a yeah it's removed so I repeat the same command and I can specify here - - post name like this say - dot example.com that's all right so if I give the host name you have got this name coming up here and if I show you at C host you will see this entry is automatically populated by that docker so these two and these two containers are obviously talking to each other because they are on the same network fair enough now the next thing is that fine we have understood all these things let's move on further and let's create our own network and then see how can we create our own network this is all which I had explained you so remember these guys and if I give the docker inspect command again I should be seeing two containers so let's check it out because I have two containers running here so if I go back here and if I give the command docker inspect network and the bridge whatever sorry you can see there I have got two containers running so two containers are a part of this network so this way the things keeps on updating okay so let's create our own network and try to run one container here and I had already explained you I can again reconfirm it by giving the BRC TL show command this is going to be interesting so if I give the command V our CTL shows docker 0 it shows you that I have got 2 wet interfaces connecting to dock or 0 and these two wet interfaces represent each of the containers and I sees right so how can I create my own network our own network so we had already gone through this there is a very simple command docker network create the driver should be bridge because it's a host only network and then feel free to assign any name to it so I can also specify my own IPS and stuff like that so I can get the come on talker Network create I give network nuts is the name of new network I can specify my subnets then I can specify my IPS which IP I wanted to give like this and I can if you wish you can also specify the Gateway go do a back slash share and put a - - gateway 10 dot say zero dot one hundred dot hundred anything right so in this way you can assign it so if if I give the command docker network list you will see one network nuts is coming up and if I inspect this dr. netbook inspect and say Network nuts so you will find I have this subnet and the Gateway and all the things and obviously I don't have any containers here so let's run one container inside it so it's very simple why creating the network what I do let me just close one container one of the one so now I've got only one container running which is name is to fair enough so I can then run a container inside it all you have to do is while using the docker run command the docker inspecting is all we had already done you just need to specify - - net and the network that's all so that's let's do it right just remember this this is all you have to do and the name of the name of the network you wanted to run in so I can use the same thing one I just specify here - - net network nuts that's all that means I am binding this particular container or running this container in a different network that's it ten dot 0 dot 0 dot go back to the slides and go back to that particular picture that means this container is running here right on a different network obviously they won't be able to talk to each other why it it makes sense because they are in a different network right Roger I can remove this stuff they are all together in a different network so this 10 network will not be able to talk to 170 - fair enough right so I check it out so that this is one and this is another one so this IP is 10.0.0.0 is 10 170 2.17 dot 0.3 so I should not be able to talk to paying 172 dot 17.0 dot three because this is not connected right this is not connected man there are different networks how can I make two containers running in different networks talk to each other it's very simple it's very simple all I have to do is to put a line here from here that's it isn't it if I somehow able to connect this container to this network I should be then this container will have the IP from this range also right so this container will have two IDs one will be of ten range another will be of whatever IP ranges of the docker zero and then they will be able to talk to each of them so if I move down and show this to you so I just need to attach this container to to this network so I go back I open it so I run docker PS I have got one run one is in the network right yeah so what I do I give the command docker network to connect and connect to network nuts and which container one oh sorry just turn it just an hour already exists in nerds dr. Network connect and this is all I have to do and let me check if if I run doctor network inspect network nuts oh sorry sorry sorry I'm sorry I have to connect the one to the default one solid soil under lien I do stupid things yeah perfect so I was just a bit confused between the network names and the content and the containers names so what I had done I had connected the container one to the network bridge so that means I just drawn this line right this is the bridge doctor zero is the bridge I can show this if if I if I go to the one this is the one right having the IP of 10 so if if I give the command again IPS you will see it has got one more I'd be available to it from the bridge Network now it has got the IP two and the this one has got IP 3 so they should be able to talk to each other pin 172 dot 17.04 3 yes they are able to talk to each other and I can reconfirm it by inspecting the network so if I give dr. Network inspect bridge you will see it has got one network sorry one container is a part of this and it has been allocated the IP address of 170 2.17 dot 0.2 so in this manner guy you should be able to make the containers which are running on the same force to talk to each other there is another option there link option but we don't use it as often right so this is what we had done and inspected it so if you remember we while creating the network we had used the bridge - - pitch the driver is bridge so by default it is bridge so these are the modes in which you can start your network the bridge is the default one right this is it then another is the host so it is not going so that machine will not be like it doesn't create any network like for it it will be using the host machine Network you can also use this option to copy the network configuration of one container to another container see here so if I give this command docker run whatever name I am running a container here the container name is sent to us and then I run another command docker run net I give container sent to us right I'm running one more container with the Ubuntu and this so what happens that this container will have the same IP address of the first container so you can also use this so it doesn't create a new network but will share it with another container and if I specify - - net none while creating the network it doesn't create any network for it so no networking will be created so remember these things guys so you should be able to understand the basic host networking on the docker container on the docker host you should be able to understand how the containers are connected to the bridge network you should be able to see the that how many containers are connected to or a part of a particular network then you should be able to create your own network run some containers in it and should be able to attach it to a different network so that two containers running in different networks should be able to talk to each other this one so if you have got this picture clear so you are through with this particular session or particular like topic so I'll see you again in the next video till then bye-bye take care god bless
Info
Channel: networknutsdotnet
Views: 7,969
Rating: 4.8600001 out of 5
Keywords: docker fundamentals, docker training videos, containers, devops training, devops classes in delhi, online devops training, networknuts, network nuts, alok srivastava, docker networking
Id: cfzrLKvF5X0
Channel Id: undefined
Length: 21min 38sec (1298 seconds)
Published: Sat Jan 19 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.