How to restart a single container with docker-compose

后端 未结 9 1859
失恋的感觉
失恋的感觉 2020-12-02 03:27

I have a docker-compose.yml file that contains 4 containers: redis, postgres, api, worker

During the development of worker, I often need to restart it i

9条回答
  •  佛祖请我去吃肉
    2020-12-02 04:08

    Since some of the other answers include info on rebuilding, and my use case also required a rebuild, I had a better solution (compared to those).

    There's still a way to easily target just the one single worker container that both rebuilds + restarts it in a single line, albeit it's not actually a single command. The best solution for me was simply rebuild and restart:

    docker-compose build worker && docker-compose restart worker
    

    This accomplishes both major goals at once for me:

    1. Targets the single worker container
    2. Rebuilds and restarts it in a single line

    Hope this helps anyone else getting here.

提交回复
热议问题