docker-compose up/down just one container

I have not been able to find a way to up/down just one container in a docker-compose.yml file. I can off-course start and stop a single container, but I cannot make changes to a containers configuration between restarts (environment variables, mount points etc.)

What am I missing here? What is the best practice in this case?


Solution 1:

I had this need recently and solved it by having a separate docker-compose-production.yml file to deal with tweaks. Then remember to launch with docker-compose -f docker-compose-production.yml...

Solution 2:

I found this to have the same affect as docker-compose down for a single service:

docker-compose rm -s -v yourService

docker-compose rm

Usage: rm [options] [SERVICE...]

Options:
-s, --stop Stop the containers, if required, before removing
-v Remove any anonymous volumes attached to containers

You can condense all the flags into a single - param: docker-compose rm -sv yourService

Solution 3:

I would suggest you check out this excellent thread on stackoverflow.com. The quick answer here to rebuild the single container and restart it is:

docker-compose up -d --build worker

This would be the ideal solution if, for example, your changes involved your Dockerfile and not just docker-compose.ymll

Solution 4:

You can use

$ docker-compose -f docker-compose.yml up yourService

to start just yourService and all dependencies required by it.

So if yourService depends on mysql container, the above command would start both the containers.