[Intro Music]
All right, I have just rearranged
those two windows and stacked on
top of each other in order to be
able to leave my face here in this
corner. So let's proceed. And in
this lecture, let's create the two
different containers based on nginx
image. And for that we will serve
files from different folders. Let's
get right into it. Let's go to
Visual Studio Code, and recap that
there was 'containers' folder on
Desktop; and inside of it, there
was nginx folder. And we have used
this folder in order to serve some
static files like index.html
and the favicons to clients using
nginx web server. And now it's a
good time to take this folder and
make two copies of this folder and
call them 'nginx1' and
'nginx2'. And afterwards, we
will spin up two different
containers running nginx server, and
we will expose them to do different
external ports on this computer.
Let's do so. If you don't have this
'nginx' folder, you could take it
from GitHub repository, just clone
it, find 'containers' folder there,
and then find 'nginx' folder.
Great. Let me copy this folder,
right mouse click, Copy, and paste
here like so. And let me rename it,
press Enter, and it will be 'nginx1'
like so. And let's make one
more copy, paste, and let's name it
'nginx2', like so. Next, let's open
up 'nginx1' folder, and open
index.html file there. Let's first
close this index.html file
that was opened in nginx folder.
Okay, so nginx1, and index.html.
And here let's adjust this
text, 'Hello from the FIRST nginx
server, like so. Let's save this
file. Next collapse nginx1
folder, expand nginx2 folder, and
open index.html file there. And
let's adjust text here, Hello from
the SECOND nginx server'. And also
we could adjust the titles here, and
instead of 'Document' here will
be, let's say 'NGINX2', and let's
save this file, go to nginx1
folder, and index.html file
inside of that folder, and adjust
the document here, and here will be
'NGINX1'. Let's save the file.
And now we are all set. And now we
are able to start two different
containers in two different
folders. Great. Let me close those
two index.html files, and go to
terminal. Recap that we have started
the standalone nginx container
using 'PWD' variable. And now we
will do the same. But if you want
to use variable instead of absolute
path, you need to first 'cd' to
corresponding folder that has
needed files and only then run
'docker run' command inside of that
folder. Let's do so. Here will be
'nginx1' server, and here will be
'nginx2' server. Let's 'cd' to 'Desktop/
containers/nginx1', like so. And
here let's 'cd' to 'Desktop/containers/
nginx2'. Great. Let's now start
the nginx1 container, and for
that we will use as usually 'docker
run' command. Next let's expose port
'-p', and let's run nginx1
server on port, let's say 5555, and
internal port will be 80, and
next comes volume mapping, '-v',
here will be variable 'PWD',
next comes ':', and after
':' you need to specify path to
files inside of the container. And
this path is 'usr/share/nginx/html',
like so. And finally comes name of
nginx image, 'nginx'. Also Optionally,
you could specify the name of the
container. Recap that if you don't
specify the name of the container,
then Docker will generate random
name and you have seen such random
names before. But you are able to
add custom name if you want to. And
for that you could use option '--name',
and here let's name this
container 'nginx1', like so.
Great. Let's press Enter, and see
what will happen. Container is
running. We are actually inside of
it and we are ready to see some
logs. Great. Let's now do the same
here for nginx to web server, 'docker
run -p'. Let's expose it to
port 6666 like so, and internal port
will be again 80 because that's
the port that is opened by nginx
server inside of the container by
default. Next comes the volume mapping,
same variable 'PWD', it is important,
same variable, and it will be
replaced by absolute path for each
of those folders - nginx2, and
nginx1 in our case. And here,
let's after colon specifies same
internal folder, '/usr/share/nginx/
html'. And let's give name to this
container 'nginx2 nginx'. Okay,
let's press Enter, and start this
second nginx server. Now we are all
set. And those two containers are
now running. And in order to verify
it, you can simply open up Google
Chrome and try to connect to those
two ports, 5555 and 6666. Let's do
so. Let's go to Google Chrome, and
here we could use a localhost. But
recap that you're also able to use
a loopback IP address 127.0.0.1 or
any of the IP addresses of your
computer. I'll use a localhost, so
'localhost', and here let's
connect to first nginx server.
'Hello from the FIRST Nginx server!'.
Let's open up a new tab. 'localhost
:6666'. 'This site can't be reached',
something is wrong. Let's go to
terminal and verify what's actually
happening here. '/usr/share/nginx'.
[no audio]
No logs here. And the command seems
working properly. Let's go back
to Chrome. Yeah, and actually, I
see here error, 'ERR_UNSAFE_PORT'.
It seems that I'm not able to
expose the such port, 6666. Okay,
let's rerun this container, and use
another port. Let's close this, and
let's run it at port, let's say
7777. And I see error from Docker,
'Error response from daemon:
Conflict. The container name "/nginx2"
is already in use by another
container'. But actually, I have
just stopped this container with
custom name. But it still exists
and you are able to start it over
again. You could verify that by
entering 'docker ps', and you should
see only one container running, and
yes, that is a case here we see
this container that is running here
in this window. But if you type
'docker ps -a', you will see that
this container, it should be
somewhere at the top, was exited,
but it is still available for use,
and you are able to restart if you
want to. Here was actually this
container with name 'nginx2'.
That's why we need to remove this
container first before starting
container with the same name. And I
could remove container by typing
'docker rm', and here will be either
ID of the container or its name, we
could use here name, 'nginx2', like
so. Container was removed. And now I
am able to try to start
container with the same name again.
Let's clear terminal here, and
again go back to history and find
this command. And let's try to start
this container and expose port 7777,
Enter, let's go to Chrome, and
here instead of this port, let's
use this port, Enter, and I see
response, 'Hello from the SECOND
Nginx server!'. Basically I have no
idea why port 6666 is considered
unsafe. Actually, let me Google it
quickly, '6666 unsafe port', and
let's check out this first link,
'Which ports are considered unsafe
by Chrome?' We'll scroll down a bit,
and here is a list of all ports
that are considered as restricted.
Actually, you see here a list of
default ports for different
applications like Port 22 for 'ssh',
and so on. And let me scroll down
and yes here is the list of ports in
this range. And this port 6666
is an 'Alternator IRC [Apple addition]' port.
Actually I don't know what is IRC,
let me check what is that quickly.
IRC is Internet Relay Chat, is a
system that facilitates transfer
messages in the form of text'. Okay,
it's some sort of chatting
application. Great. That's how we
found out that we are not able to
expose such port and use it for
our nginx server, or any other
container basically. Great. We have
achieved actually our goal, and we
are able to summarize what we have
achieved in this lecture. And we
have created two different nginx
servers here with first server and
we have served content from the
'nginx1' folder, and here was
the second nginx server and it
serves content from the nginx2
folder, and here we have actually
verified that. Here you see, 'Hello
from the SECOND Nginx server!'; and
here is the document title, NGINX2;
and here in this tab you see
document title, 'NGINX1', and
'Hello from the FIRST Nginx
server!'. And of course, anytime when
you edit the files in those two
folders, and refresh the page
afterwards in Google Chrome, you'll
see updated page. For example, if I
change index.html file here in
nginx2 folder, and add one more
exclamation mark here, go to Google
Chrome back, go to nginx2,
refresh page, you will see
updated text here. That's how
you're able to start multiple
nginx servers. But it is
important that you need to use
different external ports, because
on your computer, each port may be
utilized only by one application.
And in this case, those two ports,
this port and this port will be
actually forwarded to Docker host
and it will actually proxy those
ports to corresponding containers.
That's how it works under the hood.
Great. That's all for this lecture.
I hope that you have enjoyed it, and
we've found some interesting stuff.
And in the next lecture, let's
start with Python; and let's create
a simple Python application and run
it inside of the container. I will
see you in the next lecture. Bye-Bye.
[no audio]