如何使用docker-compose在不停机的情况下重建和更新容器? [英] How to rebuild and update a container without downtime with docker-compose?
问题描述
我非常喜欢使用docker-compose。
I enjoy a lot using docker-compose.
例如。在我的服务器上,当我想对我的应用进行较小的更改时,我只需要 git pull origin master&& docker-compose restart
,工作正常。
Eg. on my server, when I want to update my app with minor changes, I only need to git pull origin master && docker-compose restart
, works perfectly.
但是有时候,我需要重建(例如,我添加了一个npm依赖项,需要运行 npm install
)。
But sometimes, I need to rebuild (eg. I added an npm dependency, need to run npm install
again).
在这种情况下,我要做 docker-compose build --no-cache& docker-compose restart
。
In this case, I do docker-compose build --no-cache && docker-compose restart
.
我希望这样做:
- 创建我的容器的新实例
- 停止现有容器(在完成更新后)
- 启动新容器
- 可以选择删除旧的,但是可以手动完成
- create a new instance of my container
- stop the existing container (after the newer has finished building)
- start the new one
- optionally remove the old one, but this could be done manually
但实际上似乎重新启动了前一个。
But in practice it seems to restart the former one again.
这是预期的行为吗?
如何处理重建并在构建后的 之后开始新的重建?
How can I handle a rebuild and start the new one after it is built?
也许我错过了一个特定的命令?还是有道理?
Maybe I missed a specific command? Or would it make sense to have it?
推荐答案
您的docker-compose.yml配置中,这些
的更改在运行此命令后不会反映出来。
If you make changes to your docker-compose.yml configuration these changes will not be reflected after running this command.
您应该能够
$docker-compose up -d --no-deps --build <service_name>
-不滴水
不会开始链接服务。
这篇关于如何使用docker-compose在不停机的情况下重建和更新容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!