Filip Ion Dorinel
Filip Ion Dorinel

Reputation: 349

Docker Run-time Configuration File

I am a docker beginner working on containerizing an application and I am looking for a solution to pass a specific configuration file to each container.

What I need for my application is a JSON file to be copied from the host to the container based on the value of an environment variable when the container starts. This file should be instance specific so I can't include it in the image.

Could you please help me with some suggestions on how to accomplish that?

Thank you!

Upvotes: 4

Views: 2561

Answers (1)

yamenk
yamenk

Reputation: 51768

You can mount the directory that contains your json file into the container when running the container using the volume option:

docker run -v /host/config:/config myImage

If the directory on the host is specified using an environment variable, you can replace /host/config with $CONFIG_LOCATION where CONFIG_LOCATION is a env variable defined on the host.

If the env variable does not map directly to the location of the config on the host machine, create a script that resolves the host config location from the env variable and at the end call the above command

Upvotes: 2

Related Questions