Reputation: 190
I have a Node.js application which is built into the docker image. In this application I have a config file with some API urls (API key, for example) which might change from time to time. Is it possible to launch the docker image with some additional parameter and then access this param from the node.js code (I assume this could be done through using environment vars) so as not to rebuild the image every time the value of this param should be changed. This is the pseudo code which I assume can be used:
docker run -p 8080:8080 paramApiKey="12345" mydockerimage
and then I'd like to access it from the node.js app:
var apiKey = process.env.paramApiKey
Can this somehow be achieved?
Upvotes: 2
Views: 4249
Reputation: 21789
In order to define environment variables with docker at the time you use the run
command, you have to use the -e
flag and the format is should be "name=value"
, meaning that your ENV variable should be "paramApiKey=12345"
so that you can access it by doing process.env.paramApiKey
in your application.
That being said, your command would look like:
docker run -p 8080:8080 -e "paramApiKey=12345" mydockerimage
Upvotes: 4
Reputation: 6132
Sure, just try:
docker run -p 8080:8080 -e "paramApiKey=12345" mydockerimage
Upvotes: 1