-: The running theme that we have seen with Docker Compose
is that it makes it a lot easier
to work with multiple containers at the same time.
In this section,
we're gonna take a look at two different commands
that we had previously used with Docker CLI,
and get a sense of how to run them
with Docker Compose instead.
So the two commands we're gonna look at,
well just the first one for right now,
we'll move on to the second one in just a moment.
I want you to recall that in the past we executed a,
or created a container by running docker run -d,
and then the name of an image, like say Redis.
This started up a new container,
but it executed it in the background so we could continue
running commands in this terminal window if we wanted to.
We could then get a printout
of all of our running containers with docker ps,
so there's the container I just created.
And I could then stop that container by copying the ID
and executing docker stop and pasting the ID.
Now you can kind of imagine
that when we start using Docker Compose
and we're working with multiple images
or multiple containers at the same time,
it would really be a pain to have to run docker stop
with each different ID for each container we started.
So with Docker Compose,
we can automatically start up multiple containers
in the background at the same time,
and then close them all at the same time
with one single command.
So here's how we do it.
To start up a group of containers in the background
using that -d flag before, like we did with Docker CLI,
we can run docker compose up and then -d on the very end.
We can then stop all of our running containers
with docker compose down.
An easy way to remember down right here is that hey,
docker compose up, the opposite of going up is going down.
So let's try this out.
Still inside of my visits directory,
I'll run Docker compose up -d.
That's gonna start up
both of my containers in the background
so I can continue running other commands here.
I can do a docker ps,
that'll show our two running containers.
And then to stop both of them at the same time
we can do a docker compose down like so.
And when I run that, it's gonna stop
and then remove the two containers we had created.
So if I do another docker ps, nope, nothing's here anymore.
All right, so that's pretty much it.
Again, there's a lot of commands from the Docker CLI world
that have kind of a one-to-one translation
over to Docker Compose.
So let's take a quick pause right here,
and we'll continue looking at a couple of other commands
in the next section.