这里对 Docker 来说是全新的。我在远程虚拟机上运行 Docker,并在其上运行一个虚拟容器(我可以通过发出 docker ps
命令来验证容器是否正在运行)。
我想通过为 docker
用户提供非 root 访问权限来保护我的 Docker 安装:
sudo usermod -aG docker myuser
但我担心在任何容器运行时都会乱用 Docker,以防“热部署”产生问题。所以这让我想知道,一般来说:如果我想在 Docker(我认为是守护进程)上执行任何类型的操作工作,同时有事件容器在其上运行,我必须做什么?是否需要先停止/停止所有容器?或者 Docker 会继续运行并在适当的时候应用更新吗?
容器本身也是如此。假设我有一个部署到 Docker 守护进程的 myapp-1.0.4
容器。现在我想部署 myapp-1.0.5
,这是如何工作的?我是否需要停止 1.0.4
,将其从 Docker 中删除,然后部署/运行 1.0.5
?或者 Docker 是否在幕后为我处理这个问题?
最佳答案
if I want to do any sort of operational work on Docker (daemon, I presume) while there are live containers running on it, what do I have to do? Do all containers need to be stopped/halted first? Or will Docker keep on ticking and apply the updates when appropriate?
通常,所有容器都会首先停止。
这种情况通常发生在我升级 docker 本身时:我发现所有容器都停止了(除了 data containers, which are just created ,并且仍然如此)
Say I have a myapp-1.0.4 container deployed to a Docker daemon. Now I want to deploy myapp-1.0.5, how does this work? Do I stop 1.0.4, remove it from Docker, and then deploy/run 1.0.5? Or does Docker handle this for me under the hood?
这取决于您的应用程序的性质和要求:对于完全无状态的应用程序,您甚至可以运行 1.0.5(将不同的主机端口映射到您的应用程序公开的端口),对其进行一些测试,然后停止 1.0.4当您认为 1.0.5 已准备就绪时。
但是对于具有任何类型的共享状态或资源(已安装的卷、共享数据容器等)的应用程序,您需要停止并 rm 1.0.4,然后才能从 1.0.5 镜像启动新容器。
(1) why don't you stop them [the data containers] when upgrading Docker?
因为......它们从一开始就没有开始。
在容器的生命周期中,您可以创建、启动、运行容器。但根据定义,数据容器没有要运行的进程:它只是公开 VOLUME
(S),供其他容器挂载 (--volumes-from
)
(2) What's the difference between a data/volume container, and a Docker container running, say a full bore MySQL server?
区别在于,数据容器不运行任何进程,因此当所述进程停止时它不会退出。这种情况永远不会发生,因为没有进程可以运行。
只要服务器进程不停止,MySQL 服务器容器就会一直运行。
关于docker - 动态部署对 Docker 及其容器的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32666636/