简体   繁体   English

如何在生产环境中快速切换 Docker 容器?

[英]How to quickly switch Docker containers on production?

Imagine that i had created service for uploading kittens pictures and use Docker container on production.想象一下,我创建了用于上传小猫图片的服务并在生产中使用 Docker 容器。 To do it I created Docker image with PHP 5.5 service, mounted "upload" folder of my app from real OS and also mounted folder with source code.为此,我使用 PHP 5.5 服务创建了 Docker 映像,从真实操作系统安装了我的应用程序的“上传”文件夹,还安装了带有源代码的文件夹。 After some time I decided to improve my app, changed source code and now it requires different env from existed in Docker.一段时间后,我决定改进我的应用程序,更改源代码,现在它需要不同于 Docker 中的环境。 For example, now I need PHP 5.6 instead of PHP 5.5例如,现在我需要 PHP 5.6 而不是 PHP 5.5

So when I want to change source code of my app, I can do it by switching mounted source code folder with symlinks (or cannot, because Docker will keep socket? If so, how to switch source code? Should I do it right in container without mounting?).因此,当我想更改我的应用程序的源代码时,我可以通过使用符号链接切换挂载的源代码文件夹来实现(或者不能,因为 Docker 会保留套接字?如果是这样,如何切换源代码?我应该在容器中正确操作吗?没有安装?)。

But how can I quickly switch Docker container after switching source code?但是切换源码后如何快速切换Docker容器呢?

Fastest way would be to exec a shell session in the container, update the environment, restart the php service.最快的方法是在容器中执行一个 shell 会话,更新环境,重新启动 php 服务。 As you have mounted the source code, no need to switch.由于您已经挂载了源代码,因此无需切换。

Best way would be to create a docker image with required environment and stop previous container then run the new image mounting appropriate directories.最好的方法是创建一个具有所需环境的 docker 镜像并停止之前的容器,然后运行新的镜像挂载适当的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM