Docker-无需运行命令即可更改现有容器设置
是否可以更改docker容器的设置,例如entrypoint
,ports
或memory-limits
而无需删除容器并使用Docker Run 命令?示例:
docker stop< container_id>
,更改设置,然后更改docker start&container_id>
?
当您使用Docker Run -D Image_name
时,某些图像会从开始时初始化,因此我无法使用相同的卷。
是否可以通过停止容器而不是重新运行来更改设置?
Is it possible to change the settings of docker container like entrypoint
, ports
or memory-limits
without having to delete the container and run using docker run
command? Example: docker stop <container_id>
, change settings and then docker start <container_id>
?
When you use docker run -d image_name
, some images tries to initialize from start and as a result I can't use the same volume.
Is it possible to change the settings by stopping the container instead of re-run?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要停止,删除和重新创建容器。
这不是Docker的特殊性。如果您在任何类似Unix的环境中运行任何命令,并且要更改其命令行参数或环境变量,则需要停止该过程并创建一个新的过程。 Docker容器是围绕一个过程的包装器,并具有一些其他隔离功能,对于许多例行的东西,您需要删除容器。在诸如Kubernetes之类的集群容器环境中,这足以使更改部署对象的任何属性会导致所有关联的容器(Kubernetes Pods)自动重新创建所有相关的容器。
存在少数Docker命令,但几乎从未在正常操作中使用。
docker start
在其中;只需在文档中跳过它即可。实际上,
Docker Run
的正常行为是,您始终从已知的“清洁”初始状态开始程序;这比试图从应用程序的上一个运行中恢复的任何状态更容易设置为应用程序开发人员。如果您需要调试图像启动,那么一件简单的事情就是告诉容器运行交互式外壳而不是其默认命令
(某些图像可能具有
bash
可用的可以更舒适地使用;某些图像可能需要尴尬的docker run -Entrypoint
选项。)在此外壳中,您可以尝试手动运行容器启动命令并查看会发生什么。您不必担心以任何特定的方式损坏容器代码,因为在容器退出后,您在此外壳中更改的任何内容都会丢失。You need to stop, delete, and recreate the container.
This isn't specific to Docker. If you run any command in any Unix-like environment and you want to change its command-line parameters or environment variables, you need to stop the process and create a new one. A Docker container is a wrapper around a process with some additional isolation features, and for a great many routine things you're required to delete the container. In cluster container environments like Kubernetes, this is routine enough that changing any property of a Deployment object will cause all of the associated containers (Kubernetes Pods) to get recreated automatically.
There are a handful of Docker commands that exist but are almost never used in normal operation.
docker start
is among these; just skip over it in the documentation.In fact, the normal behavior of
docker run
is that you're always beginning the program from a known "clean" initial state; this is easier to set up as an application developer than trying to recover from whatever state the previous run of the application might have been left in.If you need to debug the image startup, an easy thing to do is to tell the container to run an interactive shell instead of its default command
(Some images may have
bash
available which will be more comfortable to work in; some images may require an awkwarddocker run --entrypoint
option.) From this shell you can try to manually run the container startup commands and see what happens. You don't need to worry about damaging the container code in any particular way, since anything you change in this shell will get lost as soon as the container exits.