docker - 如何在容器上禁用自动重启? [英] docker - how do you disable auto-restart on a container?
问题描述
我可以使用 --restart=always
启用自动重启,但是在我停止容器后,如何关闭该属性?
I can enable auto-restart with --restart=always
, but after I stop the container, how do I turn off that attribute?
我通常运行网络服务器并通常映射端口 80:
I normally run a webserver and typically map port 80:
docker run -d --restart=always -p 80:80 -i -t myuser/myproj /bin/bash
但有时我想运行我的图像的更新版本,但我想保留旧容器.问题是,如果有多个带有 --restart=always
的容器,则只有其中一个(随机?)启动,因为它们都在争用主机上的 80 端口.
But there are times when I want to run a newer version of my image, but I want to keep the old container around. The problem is that if there are multiple containers with --restart=always
, only one of them (random?) starts because they're all contending for port 80 on the host.
推荐答案
你可以使用 --restart=unless-stopped
选项,正如@Shibashis 提到的,或者更新重启策略(这需要docker 1.11 或更新版本);
You can use the --restart=unless-stopped
option, as @Shibashis mentioned, or update the restart policy (this requires docker 1.11 or newer);
参见docker update
和 Docker 重启策略.
docker update --restart=no my-container
更新现有容器的重启策略 (my-container
)
that updates the restart-policy for an existing container (my-container
)
这篇关于docker - 如何在容器上禁用自动重启?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!