简体   繁体   English

如何从已安装的卷中保留文件并使用该文件创建新容器?

[英]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.

相关问题 将文件从主机替换为已挂载卷的容器 - Replace a file from host to container with mounted volume 在容器 1 内运行的 Docker 应用程序如何从容器 2 读取文件,容器 2 是卷安装到主机的 - How does Docker App Running Inside Container 1 should read file from Container 2 which is Volume Mounted to Host Machine 启动 docker 容器并安装卷后如何保留编译文件? - How to keep compiled files after starting a docker container with volume mounted? docker 不断重启,直到在挂载的卷中创建文件 - docker keep restarting until file is created in a mounted volume 将容器中的文件移动到已安装卷的文件夹 docker - moving a file in a container to a folder that has a mounted volume docker Docker 容器入口点没有安装卷的此类文件错误 - Docker container entry point no such file error with mounted volume 尝试创建已装入卷的容器时出错 - Error when trying to create container with mounted volume 如何管理安装到 docker 容器中的卷的权限? - How to manage permissions for a volume mounted into a docker container? 如何从 docker 中检查已安装的 dockerhost 文件系统/卷上的打开文件 - How to check from within docker for an open file on a mounted dockerhost filesystem/volume 当此文件作为卷挂载时,pgadmin4 docker 容器中的 pgpass 文件在哪里 - Where is the pgpass file in pgadmin4 docker container when this file is mounted as a volume
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM