[Intro Music]
We have just successfully created
the new custom bridge network. It is
called 'custom', and this driver is
bridge. And here you'll see Subnet
that will be used for assignment of
the IP addresses to containers in
this custom network. Now let's stop
those two containers that we
have created in default bridge
network; and afterwards, let's
create again two new containers in
custom network, but we will not use
now '--name' option; and we
will not use '-h', hostname
option. We will let Docker create
custom names on its own. Great. Let
me exit from this sh shell, clear
terminal here, and let me exit from
this sh shell, clear terminal as
well, and let me actually using
'docker container prune' remove
existing containers. Yes. And
afterwards, let's clear terminal,
and start first container
here using 'docker run -it
busybox' command, like so without
name option and without h option.
But we will add additional option.
Basically let me first run here
'docker run --help'
command and show you option that we
will use now, it is '--network'
option, here it is. And
with this option, we are able to
connect container to specific
network. And again by default
without this option, containers are
attached to default bridge network.
Great. Let's use this option.
'docker run -it --network',
and after this parameter,
let's specify the name of the
custom network we want to connect
this container to. And in our case
name is simply 'custom'. Let's type
this name like so. And afterwards,
let's type the name of the image we
want to use for this container. And
name will be same as before,
'busybox'. 'busybox'. Let's press
Enter. And let's verify which IP
address was assigned to this
'busybox' container. 'hostname -i';
and here you see address
from network range that was
assigned to our custom bridge
network, this range. And if I'll
enter here, 'docker network inspect
custom', you should see now
container that was attached to this
custom network. Here are the
details about this first
container. Here is its random
name, "heuristic_lumiere'; here is
MacAddress; and here's IP address,
same as we see here in this output.
Great. Let's now in the same way,
create one more 'busybox' container.
Let's go to this step, 'docker run
-it --network',
again 'custom' here, and the name of
the container, image sorry, 'busybox',
Enter. And let's verify IP
address of this container, 'hostname
-i', 172.18.0.3. Let's go back to
this last step, and verify whether
this container was attached to this
'custom' network. And yes, now I see
here in this output two containers
with different IP addresses of
course. Here is first container.
Here it is. And here's the second
container. Here you see IDs of
containers, here ID of the first
container, and here is ID of the
second container. And here are
their IP addresses, this one and
this one. Wonderful. Let's now
verify connectivity between those
two 'busybox' containers; and first
let's as usually ping using IP
address 172.18.0.3. And yes, I get the
response from second container. And
now let's try to ping by hostname.
Let's check hostname of this
container, 'hostname' like so. Here
is hostname. Let's copy it, go
here, and use this hostname with
ping command. And now I get
response. It means that using
custom network we are able to
communicate between containers
using their hostnames. It is a
very important outcome. And that's
how picture differs from default
bridge network, where we were not
able to communicate using hostnames.
Great. Let's now verify whether we
will be able to communicate between
containers using their names. Recap
the names were assigned randomly by
Docker. Let's clear terminal, and
actually you're able to find out
which names were assigned to
containers here in this section.
Name is here for container with
this IP address. And basically its
container running in my case in
this first step; and name for second
container is here. Here it is. And
now using this name let me try to
access second container using same
ping command from first container,
this one. 'ping', and let me paste
the name of the second container;
not hostname, name; Enter; and I see
'bad address'. Great. That's outcome
we have at the moment. We are able
to communicate between containers
using their hostnames. But
hostnames are actually random. And
they are assigned randomly. And
they are actually based on ID of
specific container. Here, you see
that, 'hostname', you see first
few characters of ID of specific
container. Here is actually full
ID, here it is. And of course,
it's not convenient to use IDs for
communication between containers.
We also have just verified that we
are not able to communicate between
containers using randomly assigned
names, this name or this name. Here
you see response, 'bad address'. But
now let's try to launch same two
'busybox' containers using custom
names instead of randomly generated,
but let's try that of course after
the small pause, I'll see you in a bit. Bye-Bye.
[no audio]