Now, obviously docker-compose is a very,
very useful tool.
And docker-compose up and down,
will be our best friends when working with it.
Now, there are two other commands
or variations of commands,
which I want to show you.
And there's one other thing about the naming
of these containers and services.
Now let me start with the commons.
We saw docker-compose up and down in action.
Now for the up command,
we can also use dash dash help.
We can use this on all Docker-related commands,
although just on docker-compose,
but on the up command,
I want to use it because there's one specific option,
which we can set, which is interesting.
And that's the dash dash build option.
With the dash dash build option add it to the up command,
you force that images are rebuilt.
Otherwise, images like this backend image here,
which we do build based on our own Docker file,
will only be built once.
And if docker-composed then finds this image,
the next time it tries to start all these services,
it will reuse the existing image.
This might be what you want
and often it will not be a problem at all,
but if you want to force it to rebuild it,
because for example, you know that something changed
in code and therefore a new image should be built,
then you can force docker-compose by adding dash dash build.
Now, if you just want to build the images defined
in your docker-compose file,
and with that I'm of course only referring
to the images we build with the build key here,
not to images you point at with image,
these are images you are pulling from Docker Hub
or from some other registry
and therefore they are already build.
But for your own images,
if you just want to build any custom images
to find in a docker-compose file,
you can do that with docker-compose build.
Now, when you run up, the build step is included.
If a image needs to be built
in order to start the container, it will be built.
But if you just want to build,
without starting a container thereafter,
you could trigger this by running docker-compose build,
and now it will really just do that,
build any missing images and then not start containers.
Just build the images.
Now, thereafter of course, if I run docker-compose up
in detached mode, for example, it starts these services,
it downloads any images that might be missing.
In my case, I deleted the Mongo image off screen
and therefore it re-downloads this,
but it should not rebuild the back-end image, for example,
because we just built this and as explained a couple
of minutes ago, docker-compose will only check
if an image is there locally
and if it is it will use that and not recreate it.
Now, I also got one last note here,
and this is related to the names of the containers,
which are created and started.
You can of course see them if you run the Docker PS command.
You see, we have that running front-end,
back-end and Mongo container.
And you can see their names as well.
The front-end container was named docker-complete_front_1.
Here's the name of the backend
and here's the name of the Mongo Db container.
Now, what you will notice,
is that these are not the names we defined
in docker-compose.
There I specified Mongo Db and back-end
and front-end as names.
Well, technically these are just the service names
and they are translated to containers,
but these are not the container names therefore.
These names are just picked up in the container names.
You see that Mongo Db is part of this last name.
The full name is actually your folder name,
your project folder name,
then an underscore,
then your service name,
and then an incrementing number.
Now, if you wanna assign your own container name,
you can do this by adding the container name option here.
And if I would set this to Mongo DB here,
now I would force this name of the actual container,
which is up and running to be Mongo Db.
So if I now run docker-compose down,
and then we run docker-compose up again,
you will notice that now,
if I run Docker PS,
this Mongo Db container really has a name of Mongo Db.
Now, I will remove this because I am fine
with the auto-generated names,
I just want to show this to you,
so that you know that you can change these names.
But that's it with docker-compose for now,
it's a very powerful tool
and it allows us to build multi-container applications
on our local host machine
and start and control all the containers
together with one command and one conflict file.