简体   繁体   中英

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). 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:

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.

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. 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.

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. I have looked into using configmaps, but I'm not seeing how I can use those for this purpose.

If you can store the file into the ConfigMap you can mount the file to volume and use it inside the 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.

In this case there will be no PVC required.

You can also follow this nice example showing how to mount the file into a volume inside a 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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