Stopping and restarting the Docker Compose image

This is probably a beginner's question.. but.. that's me.

I worked through starting up the container.. and all good.. but then I needed to stop it... which also worked.

However, when I wanted to restart the docker container again, I needed to kill all of the docker processes that were still running.

I don't really know much about this.. and thought to ask for any tips on how to restart it..without needing to kill all of the processes

is this even possible?

To stop the containers

docker-compose down

To stop the containers within the directory with the docker-compose.yml file.

Then start it up again (docker-compose up -d). That is what I do.

Note that it appears in later versions of docker that docker-compose is now a plug-in, so remove the hyphen between the commands above

2 Likes

Like @gooseleggs said, to start docker as a daemon, you can pass the -d flag. Then to stop docker you need to use docker-compose down

If you run it interactively, as I often do in my videos, a simple “ctrl-c” in that window will also stop the containers. To remove the whole docker environment and start CLEAN (don’t do this unless you know you want to start clean) issue:

docker-compose down -v

This destroys your PKI, so don’t do that unless you want to really start clean ! :slight_smile:

There are mountains and mountains of pages on the internet around docker/docker-compose. Their online help is usually a really good reference Get started with Docker Compose | Docker Documentation

1 Like

Awesome… thanks so much… its really the first time I use Docker.

My next plan is Kubernetes… but I will leave that for another day :slight_smile:

One more thing you might want to be aware of is the prune option. If you do happen to docker-compose down without -v or you stop the containers manually and you decide you want to docker-compose up with a fresh instance (or if you’re just seeing some weird behavior and want to be sure you have a clean environment). I would recommend checking out these two commands:

docker network prune - Removes any networks not currently being used
docker volume prune - Removes any volumes not currently being used

Alternatively you can docker network ls or docker volume ls to list each network/volume if you want to manually delete them (in case you have other volumes or networks you want to keep).

1 Like

Awesome… thanks for sharing the extra commands… this is very helpful