简体   繁体   English

我如何重新启动我的网站并将新更改应用到 docker 容器?

[英]How can i restart my website and apply new changes to a docker container?

I want to restart my docker container to apply new changes made.我想重新启动我的 docker 容器以应用所做的新更改。 I dont want to create a new image each time i make changes rather that it will overwrite the old one and then restart the container using the rewritten one.我不想每次进行更改时都创建一个新图像,而是它会覆盖旧图像,然后使用重写的图像重新启动容器。

I have tried stopping the container, then building an image with the same name as the old one.我试过停止容器,然后构建一个与旧容器同名的图像。 i then write docker -compose up -d .然后我写docker -compose up -d Problem is this creates a new container called like -web问题是这会创建一个名为 like -web 的新容器

The standard approach is to build a new image, stop the existing server container, and then start a new container based on a new image.标准的做法是构建一个新的镜像,停止现有的服务器容器,然后基于一个新的镜像启动一个新的容器。 If you're using Docker Compose, this can be as little as如果您使用的是 Docker Compose,这可能会少至

docker-compose build
docker-compose up -d

Compare this to running a server in a compiled language like Java or Go. Here you have the exact same workflow: compile your updated sources into a new jar file or binary, stop the existing server, and start a new one.将此与使用编译语言(如 Java 或 Go)运行服务器进行比较。这里有完全相同的工作流程:将更新后的源编译为新的 jar 文件或二进制文件,停止现有服务器,然后启动新服务器。 There's not usually a reason to try to preserve the existing process and update it with new code.通常没有理由尝试保留现有流程并使用新代码对其进行更新。

In the same way, a container is a (temporary) wrapper around a single (temporary) process.同样,容器是围绕单个(临时)进程的(临时)包装器。 There's no particular reason that you need the same container;没有特别的理由需要同一个容器; in normal operation you should be able to delete and recreate a container without losing anything.在正常操作中,您应该能够删除和重新创建容器而不会丢失任何内容。 In Docker you need to recreate a container fairly routinely to change various startup-time-only options, and also to update the underlying image.在 Docker 中,您需要相当常规地重新创建一个容器,以更改各种仅启动时选项,并更新底层图像。 If you move on to clustered environments like Kube.netes this becomes even more important: you'll have multiple replicas of a container so they can't have persistent state, and it's possible for a container to be deleted and recreated outside of your immediate control.如果你转向像 Kube.netes 这样的集群环境,这就变得更加重要:你将拥有一个容器的多个副本,因此它们不能持久化 state,并且有可能在你的直接外部删除和重新创建一个容器控制。

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

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