[Intro Music]
All right, we have just made a note
of two commands that we have used for
launch of mysql and phpmyadmin
containers, and we will get back to
them a bit later. For now let's
again create two busybox
containers, and let's try to
perform communication between them
using hostnames or names of those
containers. Let's do that. Let's
launch first busybox container here,
'docker run -it busybox'. Let me
open up a new tab, and here will be
another busybox container, 'docker
run -it busybox', and let me
verify which IP addresses were
assigned to those containers,
'hostname -i', actually those IP
addresses are the same as were
assigned before. But again, the
reason for that is that there are
no other containers currently
running in our setup. If there were
additional containers with IP
addresses that are used here now,
for example, this one, then another
IP address will be assigned to
those busybox containers like
17.0.5, 17.0.6, and so on. Great. Let's
check the IP address of this
container, 'hostname -i'; and it
has address 172.17.0.2. And if you
type 'hostname' like so, you could
get hostname of this container, of
this server. Also, same here, 'hostname',
and let's now try to ping this
busybox server by using its 'hostname',
this one. Let me copy this
hostname from here, go to this
busybox container, and use same ping
command but paste now hostname
instead of IP address. Let's press
Enter, and I see answer, 'bad address';
and that means that we are not able
to connect to this busybox
container using its hostname. Let
me also show you something. Let's
open up a new tab; and 'docker ps'
here; and let's use 'docker inspect'
command; and type here ID of, for
example, this container '39'
like so. And you'll see again
IP address of this container, here
it is. Gateway, default gateway that
is same for both containers. And
here above you will see also field
called Aliases; and now it is set to
null. Now let me show you how we are
able to set custom alias for this
container. Actually let's go back
here, and let's exit from this
container, and exit from this
container as well. And now let me
type 'docker run --help', and
here in this output you should see
one option called '-h', here it is
somewhere above, '-h', and here
you see description, it is
'Container host name'. It means that
using this option you are able to
override the default hostname that
will be assigned to specific
container. Also you are able as you
already know using option '--name',
it is somewhere here, and 'n',
yes, here it is, '--name',
you are able to assign custom name
to the container. Recap that by
default Docker assigns randomly
generated name to a container. And
now let's try to use both options
'--name', and '-h
hostname', and assign custom names,
hostname, and the container name to
those busybox containers, and verify
whether something will change and
whether we will be able to connect
ping one container from another
using either container name
or hostname on that. Let's do that.
Let me clear terminal, and here will
be busybox1, 'docker run -it',
let's use first option
'--name', here let's name it
'busybox1'; and next let's use
'-h' option, it stands for 'hostname', and
here let's say I'll use hostname
'busybox-one'. I have used
different names in order to
distinguish between hostname and
the name of the container. And
finally let's use the name of the
image, it is 'busybox'. Let's press
Enter, and now we are in sh shell,
instead of this busybox1
container; and if I'll enter our
'hostname', I should see 'busybox-one';
and if I'll enter 'hostname -i',
'hostname -i', I should
see IP address of this busybox1
container. Let's do the same, and
let's create in similar way second
busybox2 container. Let's do that
here. 'docker run -it --name',
name will be busybox2,
and hostname will be busybox-two,
and here will be the
name of the image busybox. Let's
press Enter, and we are now in sh
shell here in the second container.
'hostname' will provide us hostname
of the second container, 'busybox-
two', and 'hostname -i' will
provide us IP address of this
container. Let's as before try to
ping first busybox container
using its IP address, this one in
order to verify connection between
those two containers. 'ping 172.17.0.2',
I'll get response of course. But if
I try to ping by hostname 'busybox
-one', I'll get, bad address
'busybox-one'. Same response I'll get
if I try to ping by using name of
this container. Its name is 'busybox1'.
Let's do that, 'ping busybox1',
like so; and again, bad address
'busybox1'. If I will go to this
last step, and enter here again,
'docker ps'; and afterwards, enter
'docker inspect'. 'docker inspect'; and
here let's inspect busybox1
container. By the way, notice here
custom names that were assigned to
those two containers. And that's
because we have used '--name'
option when we have started
those two containers. And here
let's inspect for example 'busybox1',
'busybox1'. I could use
either name or ID of the container.
Let's press Enter. And I see IP
address of this container. But
Aliases is still set to null. If I
will go to this first step, and try
to perform same action as we
tried on busybox2, for example,
'ping busybox2', or
'ping busybox-two', I'll get same
response, bad address. And the
reason for that is that by default
in default bridge network you
are not able to communicate between
different containers using their
names, or hostnames, that is the
rule in Docker. I don't know
whether it will change in the
future or not. But at the moment,
it is like this. Actually, if you
want to perform communication
between containers using their names,
you need to create first custom
bridge network, and then create
containers inside of that custom
bridge network. And let me next
explain you how you're able to
create custom network using the
Docker, and create new containers
inside of that custom network. I'll
see you next. Bye-Bye.
[no audio]