How to mount a config file from host to container?

I am getting an error mounting a config file, can anyone assist?

With subPath on volumeMounts I get the error:
Error: stat /var/config/openhim-console.json: no such file or directory.
I can read this file.

Without subPath on volumeMounts I get this error:
Error: failed to start container “openhim-console”:
Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused “process_linux.go:339: container init caused “rootfs_linux.go:57: mounting \”/var/config/openhim-console.json\” to rootfs \"/var/lib/docker/overlay2/7408e2aa7e93b3c42ca4c2320681f61ae4bd4b02208364eee8da5f51d587ed21/merged\" at \"/var/lib/docker/overlay2/7408e2aa7e93b3c42ca4c2320681f61ae4bd4b02208364eee8da5f51d587ed21/merged/usr/share/nginx/html/config/default.json\" caused \“not a directory\”""
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Warning BackOff 2s kubelet, ip-10-0-65-230.eu-central-1.compute.internal Back-off restarting failed container

My yaml deployment file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: openhim-console-deployment
spec:
replicas: 1
selector:
matchLabels:
component: openhim-console
template:
metadata:
labels:
component: openhim-console
spec:
volumes:
- name: console-config
hostPath:
path: /var/config/openhim-console.json
containers:
- name: openhim-console
image: jembi/openhim-console:1.13.rc
ports:
- containerPort: 80
volumeMounts:
- name: console-config
mountPath: /usr/share/nginx/html/config/default.json
subPath: default.json
env:
- name: NODE_ENV
value: development

I think the important part of the error is this one:

caused \“not a directory\”""
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

What if you use a directory?

1 Like

Thanks, that was my issue, just needed to mount the directory.

Appreciate the help!

1 Like

Glad it worked! :slight_smile:

Hi Rata,

I have another very strange thing with this topic. I am able for this to work 100% using Minikube and Virtualbox to a shared volume but I am having an impossible time on Linux.

Do you know if there are any special permissions needed for the files to be visible? I have run this on the directory I use /var/config/openhim-console

sudo chmod -R a+rwx /var/config but still I am unable to see these files from the container?

Any ideas?

Do you see errors? Do logs shoe anything?

Do you see the file and can’t read it or you don’t see it? Does it work if you use a directory in /tmp?

Thanks Rata,

It is bizzare to be honest. So the exact same json config file runs on minikube but here is what I get on the Linux instance. This is AWS Linux Bastion server.

chmod a+rw /var/config -R

Error: Error parsing your configuration file: [/usr/src/app/config/development.json]:  **EISDIR: illegal operation on a directory, read**

    at exports.File.File.loadSync (/usr/src/app/node_modules/nconf/lib/nconf/stores/file.js:170:11)

    at exports.Provider.Provider.add (/usr/src/app/node_modules/nconf/lib/nconf/provider.js:136:23)

    at exports.Provider.Provider.file (/usr/src/app/node_modules/nconf/lib/nconf/provider.js:63:15)

    at new Config (/usr/src/app/lib/config/config.js:55:21)

    at Object.<anonymous> (/usr/src/app/lib/config/config.js:72:33)

    at Module._compile (internal/modules/cjs/loader.js:701:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

    at Module.load (internal/modules/cjs/loader.js:600:32)

    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

    at Module.require (internal/modules/cjs/loader.js:637:17)

    at require (internal/modules/cjs/helpers.js:22:18)

    at Object.<anonymous> (/usr/src/app/lib/config/index.js:7:15)

    at Module._compile (internal/modules/cjs/loader.js:701:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

    at Module.load (internal/modules/cjs/loader.js:600:32)

if I use chmod 777 /var/config -R

Error: Error parsing your configuration file: [/usr/src/app/config/development.json]:  **Unexpected end of JSON input**

    at exports.File.File.loadSync (/usr/src/app/node_modules/nconf/lib/nconf/stores/file.js:170:11)

    at exports.Provider.Provider.add (/usr/src/app/node_modules/nconf/lib/nconf/provider.js:136:23)

    at exports.Provider.Provider.file (/usr/src/app/node_modules/nconf/lib/nconf/provider.js:63:15)

    at new Config (/usr/src/app/lib/config/config.js:55:21)

    at Object.<anonymous> (/usr/src/app/lib/config/config.js:72:33)

    at Module._compile (internal/modules/cjs/loader.js:701:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

    at Module.load (internal/modules/cjs/loader.js:600:32)

    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

    at Module.require (internal/modules/cjs/loader.js:637:17)

    at require (internal/modules/cjs/helpers.js:22:18)

    at Object.<anonymous> (/usr/src/app/lib/config/index.js:7:15)

    at Module._compile (internal/modules/cjs/loader.js:701:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

    at Module.load (internal/modules/cjs/loader.js:600:32)

Is it possible that a module like nconf are unable to read the file due to permissions?

Using tmp does not work either.

Sorry, I don’t follow. Where are those logs from? Running what?

It seems something at the application level, not kubernetes. Right? Can you please provide more context?

Hi Rata,

Thanks for the help, I managed to resolve it, I posted the problem and solution here. It was due to me not being on the right server.

Appreciate your assistance.

Great, thanks for sharing! :slight_smile: