如何使用 docker-compose 重新启动单个容器 [英] How to restart a single container with docker-compose
问题描述
我有一个 docker-compose.yml
文件,其中包含 4 个容器:redis
、postgres
、api
和 worker
.
I have a docker-compose.yml
file that contains 4 containers: redis
, postgres
, api
and worker
.
在开发 worker
容器的过程中,我经常需要重启它才能应用更改.有没有什么好方法可以在不重启其他容器的情况下重启单个容器(例如 worker
)?
During the development of the worker
container, I often need to restart it in order to apply changes. Is there any good way to restart a single container (e.g. worker
) without restarting the others?
推荐答案
很简单:使用命令:
docker-compose restart worker
可以设置在杀死容器之前等待停止的时间(以秒为单位)
You can set the time to wait for stop before killing the container (in seconds)
docker-compose restart -t 30 worker
请注意,这将重新启动容器,但不会重建它.如果要应用更改然后重新启动,请查看其他答案.
Note that this will restart the container but without rebuilding it. If you want to apply your changes and then restart, take a look at the other answers.
这篇关于如何使用 docker-compose 重新启动单个容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!