50

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?

2

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...

| improve this answer | |
  • How does this work when it comes time to do docker-compose down? Wouldn't it bring down all the containers which have been brought up in all .yml files? – Jordan Morris Sep 15 '17 at 10:17
  • 2
    You can do docker-compose -f docker-compose-production.yml down – icarito Sep 17 '17 at 18:20
  • 2
    And where do you specify the container you would like to get up/down? -f is the selector of compose file, not container. – astrowalker Dec 11 '19 at 12:02
58

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

docker-compose rm -f -s -v yourService

docker-compose rm

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

Options:
-f, --force Don't ask to confirm removal
-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 -fsv yourService

| improve this answer | |
  • 1
    I think disposes the disk, btw – Jordan Morris Sep 5 '18 at 12:02
  • 2
    Could you please explain the flags, what they would do? – Semo May 22 '19 at 13:23
  • Jordan Morris, according to the manual -v disposes of anonymous volumes only when used with 'rm'. When used with 'down' it is stronger, also disposing of named volumes. The former is pretty safe. – Markus-Hermann Aug 7 at 12:47
25

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

| improve this answer | |
8

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.