I can enable auto-restart with --restart=always, but after I stop the container, how do I turn off that attribute?
I normally run a webserver and typically map port 80:
docker run -d --restart=always -p 80:80 -i -t myuser/myproj /bin/bash
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.
解决方案
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)