问题描述
我可以使用-restart = always
启用自动重启,但是在停止容器之后,如何关闭该属性?
I can enable auto-restart with --restart=always
, but after I stop the container, how do I turn off that attribute?
我通常运行Web服务器并通常映射端口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 --restart=no my-container
更新现有容器(我的容器
)的重启策略
that updates the restart-policy for an existing container (my-container
)
这篇关于docker-如何禁用容器的自动重启?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!