I am using Docker to build a Node app image. I am having my configurations in a YAML file which is located at source_folder/config.yaml
.
When doing await readFile(new URL('../config.yaml', import.meta.url), 'utf8')
in my index
file it says file not found after running. However, doing - COPY config.yaml ./
in Dockerfile
solves it but I don't want to copy my credentials in the image build.
Is there any solution I can load the config file after building the image?
Using ESM.
CodePudding user response:
I use dotenv
to load my env variables. I understand the need to not include it in builds. Docker provides a runtime solution of including these variables to your env by passing the file as an argument. So this is what I do to load my env while using docker run
:
docker run -e VARIABLE_NAME=variable_value image_to_be_executed
# or
docker run --env-file path_to_env_file image_to_be_executed