我很难理解何时重新启动容器以及何时构建新容器。
想象一下,我有一个 web 应用程序,我将其数据提供给一个容器(通过指向当前部署的符号链接)。现在,当新部署出现时,我有两个选择:(1)从映像构建新容器或(2)简单地重新启动正在运行的容器。
我知道这个决定取决于各种事情,但我的问题是一个更具概念性的问题:
什么是更好的做法,或者 Docker 的使用方式是什么?您是否发现其中一种方法有任何问题?
我很难理解何时重新启动容器以及何时构建新容器。
想象一下,我有一个 web 应用程序,我将其数据提供给一个容器(通过指向当前部署的符号链接)。现在,当新部署出现时,我有两个选择:(1)从映像构建新容器或(2)简单地重新启动正在运行的容器。
我知道这个决定取决于各种事情,但我的问题是一个更具概念性的问题:
什么是更好的做法,或者 Docker 的使用方式是什么?您是否发现其中一种方法有任何问题?
I think that both options can have the same result in some cases.
Anyway, I think that the correct approach is to prepare an image with all your prerequisites and dependencies. This is your inital state that you want to use for your webapp. Then you can start your webapp in one or many containers based on this same image. Every instance has own unique container.
In case of deploy I think that you should do a "fresh start": stop and discard running container and create a new container with your new deployed app.
Sure, you can just restart the container, but every container has a state and - in general - you want to throw this state away and start again with your fresh initial image. Of course, if your app just printfs "Hello World", there is no state saved in container, so in this case both options behave the same.