[Intro Music]
I just made a quick overview of the
mongo and mongo-express official
Docker images; and now it's time to
create two additional services in
our own 'docker-compose' file; and add
there mongo and mongo-express
services. In order to save some
time, let's simply grab those lines
from this example and insert them
to the 'docker-compose' file. Let's
go there, and let's insert those
services below 'api' here. Make sure
that you go to the same level as
'api' and 'frontend' services here in
this YAML file, and paste copied
lines like that, and make sure that
formatting is correct. And let's of
course make some adjustments here.
First service is mongo; and here
we specify image. And it means for
Docker, that we want to use
official image from the Docker Hub.
Here is name of such image. And
if you want you could also add here
tag 'latest', but we will omit it, in
such case Docker will add tag
'latest' automatically. Let's keep
'restart: always' here and here same
as in the example. In such case, Docker
will restart containers
automatically, in case of any
failures. 'environment' variables here
will be kept as you see here. But
let's change this 'example' password
to another, let's say, 'very-
strong-db-password', like
that. And also, let's take this
password and insert it here instead
of this 'example' password. Also, here
in mongo-express section, let's add
one more environment variable
called 'ME_CONFIG_
MONGODB_
SEVER:', and value will be
'mongo'. It is name of that 'mongo'
service here. And I told you in the
previous lecture that such mongo
hostname inside of the Docker will
be resolved by DNS of the Docker,
to corresponding IP address of the
running container, container that
will be running mongo service. And of
course, I'll show you how it looks
from inside. Also, here, you see
port mapping; and internal port 8081
inside of the mongo-express is
mapped to external port on your
computer 8081. And that means
that you will be able to access
graphical user interface of the
mongo-express because it has
actually GUI. It is based on the
express and Node.js, and it means that
you will be able to access it in
any web browser using localhost
:8081 address. But
notice that mongo doesn't have any
exposed ports. It does not mean
that the mongo does not utilize
ports. Of course, it uses
corresponding ports in order to be
able to accept incoming requests.
But mongo will not be exposed to
outside world. It will be available
only from other containers, for
example, from mongo-express, or from
'api', because usually 'api' servers
communicate directly with
databases. And in our project 'api'
container should interact with
mongo container, and it is possible
inside of the Docker, using mongo
as a hostname of the mongo
container. And again, there is no
need to expose mongo to outside
world, and to add port mapping.
mongo-express will communicate with
mongo internally. Alright, that's
actually all configuration that
needs to be done in order to bring
up two additional services, mongo
and mongo-express. And basically, let
me add one more instruction here,
and it is called 'depends_
on', and with such instruction in
place, you could add list of the
containers that current container
depends on. And with such
configuration, if you enter here,
for instance, mongo, mongo-express
container will be started by
Docker, only after the start of the
mongo container. That's what 'depends_
on' instruction means. That's why
let's give this instruction here.
We want to start mongo-express
after mongo; and let's save changes
here in this 'docker-compose' file.
Now, there are four different
services frontend, api, mongo and
mongo-express. Let's now go ahead
and using 'docker-compose up'
command, bring up those two
additional services. But let's do
that of course after the small pause.
[no audio]