0

If I make changes to my docker-compose.yml (say, change which host port a container port is exposed on), can I recreate that single container or do I need to restart the whole stack?

docker-compose stop ; docker-compose up will do the job but I want to avoid restarting the rest of the services. I also want to avoid deleting volumes associated with the service that I'm restarting, so docker-compose kill <service> ; docker-compose rm is not an option.

2 Answers 2

1

Just run docker-compose up again. Everything that is impacted by your change (container, volume, network, etc.) is going to be recreated, the other containers will stay.

If you want to use newer images, run docker-compose pull beforehand.

1
  • I have env_file: -myenv in compose.yml, changes to that file are ignored by 'docker compose up' Dec 17, 2022 at 13:41
0

Sometimes changes to some env file are ignored. Then I do

docker stop mycontainer
docker compose up

this will restart single container plus dependent containers which is what you do. Avoiding restarting dependent containers is bad idea, because mycontainer will come up with different docker ip

having some kind of reload command would be nice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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