2

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.

rbl9069
  • 23
  • 1
  • 5

1 Answers1

1

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.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • Thank you for this suggestion, I see how this should work. Not quite there yet, but will report back. – rbl9069 Apr 22 '21 at 08:39
  • @rbl9069 sure please let me know if get stuck or face issue anywhere. – Harsh Manvar Apr 22 '21 at 08:41
  • 1
    I was able to use configMap to mount a config file to a destination in another container, and then read it. So your solution worked for the question I asked, just not for the original container I was having trouble with. This helped me realize that the issue is with the container image itself, and I am taking this with the vendor. – rbl9069 Apr 23 '21 at 14:24