And now the question is,
how do we start services with docker-compose?
To start services with docker-compose,
we of course need the terminal,
navigated into the folder where
this docker-compose file sits,
so navigated into your project,
and now it's just one command.
docker-compose up.
And this will start all the services
to find in this compose file.
And it will not just start the containers,
it also will pull and build
all the images that might be required.
And to show this as well,
I'll also run docker image prune,
to remove all images, actually docker image prune-a,
to really remove all images,
so that I clear all images I have on my system,
so that I start from scratch again,
I'll also run docker container prune,
to remove all stopped containers,
and now let's make sure we have no running container either,
That looks good.
So with that all cleared and cleaned up,
we can now run Docker-compose up,
and hit Enter, And now this does all the setup work
that is required.
And if we scroll up a bit,
got quite a bit of output here.
If we scroll up quite a bit,
we can see that here I ran docker-compose up,
then it created a network docker-complete default,
and so it takes your project folder name,
in my case that is docker-complete,
and then attaches underscore default here,
So it creates that network,
It creates the data volume,
naming it "Docker-complete_data" though .
So this is all prefixed by your project folder name,
and then starts listening to that service.
So by default, it starts in attached mode.
Now this allows us to shut everything down
by pressing Ctrl+C, now it stopped that container,
and now if we inspect all containers,
we see that this container is stopped,
But if we don't want to start in detached mode,
we can also run docker-compose up -d,
to start in detached mode.
And if we do that, it will now start again,
and then hand control back to us.
And if we now want to stop all services
and remove all containers and so on,
we would run docker-compose down.
And this deletes all containers,
although the default network it created,
and shuts everything down.
It does not delete volumes though.
If you want to do that,
you need to add the -v flag here,
then it also removes the data volume here.
So with -v, you also remove volumes without -v,
you don't do that.
Which makes a lot of sense,
because typically you want to persist data with volumes,
So if volumes would be deleted,
if you bring your services down, that would be bad.
So long story short, docker compose-up,
and docker-compose down are your friends,
docker-compose up for building and pulling all the images,
and then starting a container,
and docker-compose down for stopping
and removing all containers, and so on.
This is how you use the docker-compose yaml file.
And with that done, let's now move on to the back end.
And let's see how we can actually
move that to docker-compose.
because at the moment, of course only the database,
is running, and that's not enough.