[英]How to keep file from mounted volume and create new container with that file?
I have a docker container image that requires me to mount a volume containing a specific configuration file, in order for that container to properly start (this image is not one that I have control over, and is vendor supplied).我有一个 docker 容器映像,需要我挂载包含特定配置文件的卷,以便该容器正确启动(此映像不是我可以控制的,而是供应商提供的)。 If that volume is not mounted, the container will exit because the file is not found.如果该卷未挂载,则容器将退出,因为找不到该文件。 So I need to put a configuration file in /host/folder/
, and then:所以我需要在/host/folder/
中放置一个配置文件,然后:
docker run --name my_app -v /host/folder:/container/folder image_id
The application will then look in /container/folder/
for the file it needs to start.然后应用程序将在/container/folder/
中查找它需要启动的文件。
I want to create/commit a new image with that file inside /container/folder/
, but when that folder is mounted as volume from the host, docker cp
will not help me do this, as far as I have tried.我想在/container/folder/
使用该文件创建/提交一个新图像,但是当该文件夹作为卷从主机安装时, docker cp
将无法帮助我做到这一点,据我所知。 I think, as far as docker is concerned, the file copied there is no different than the files in the mounted volume, and will disappear when the container is stopped.我认为,就 docker 而言,复制的文件与挂载卷中的文件没有什么不同,并且在容器停止时会消失。
Part of the reason I want to do this, is because the file will not be changed, and should be there by default.我想这样做的部分原因是因为文件不会被更改,并且默认情况下应该在那里。 The other reason is that I want to run this container in Kubernetes, and avoid using persistent volumes there to mount these directories.另一个原因是我想在 Kubernetes 中运行这个容器,并避免在那里使用持久卷来挂载这些目录。 I have looked into using configmaps, but I'm not seeing how I can use those for this purpose.我已经研究过使用 configmaps,但我没有看到如何将它们用于此目的。
If you can store the file into the ConfigMap
you can mount the file to volume and use it inside the Kubernetes.如果您可以将文件存储到ConfigMap
中,则可以将文件挂载到卷并在 Kubernetes 中使用它。
I am not sure with the type of file you have to use.我不确定您必须使用的文件类型。
ConfigMap
will inject this file into the volume of a POD so the application could access and use it. ConfigMap
会将此文件注入到 POD 的卷中,以便应用程序可以访问和使用它。
In this case there will be no PVC required.在这种情况下,将不需要 PVC。
You can also follow this nice example showing how to mount the file into a volume inside a pod.您还可以按照这个很好的示例来展示如何将文件挂载到 pod 内的卷中。
OR或者
Also, I am not sure about the docker image but if you can use that docker image you can add the file into the path, something like:另外,我不确定 docker 图像,但如果您可以使用该 docker 图像,您可以将文件添加到路径中,例如:
FROM <docker image>
ADD file ./container/folder/
In this case, you might have to check you can use the vendor docker image as a base and add the file into it.在这种情况下,您可能需要检查是否可以使用供应商 docker 映像作为基础并将文件添加到其中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.