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.

Tom
  • 327
  • 2
  • 11

2 Answers2

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.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
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

Pavel Niedoba
  • 233
  • 1
  • 3
  • 10