Reputation: 805
Let's say I have a config file in my docker container located here:
/opt/jboss/bin/config.xml
The Config file looks like this:
<Database-Password>$PASSWORD</Database-Password>
I want to pass the actual password in when I go to run the docker container using the "--env-file" argument.
This is the contents on the env-file I'm passing in:
PASSWORD=MyPassword
I understand the VARIABLE=VALUE syntax. "MyPassword" is the value of the Password variable.
How will docker know to find the specific file (/opt/jboss/bin/config.xml) with this variable and swap it out? Am I declaring the variable correctly in the config file? For some reason I'm having trouble finding this information.
Upvotes: 1
Views: 1973
Reputation: 53478
The short answer is - it won't necessarily. Unless you have some mechanism to rewrite your config file from the host environment.
This is pretty easy in a shell script - you can just refer to it as you have done.
But an XML file isn't "run" in that sense, so it probably won't just work.
As an example - if you want to 'edit' your xml, you could do it with perl
- but you'll have to install a bit more stuff to get it to work:
perl -MXML::Twig -e'XML::Twig -> new ( twig_handlers => { Database-Password => sub { $_ -> set_text ( $ENV{PASSWORD} ) } } ) -> parsefile_inplace("/opt/jboss/bin/config.xml")'
(This will need both perl
and XML::Twig
installing, so there may be better options)
Upvotes: 1
Reputation: 32156
the syntax in your env file should be
variable=value
see the doc at https://docs.docker.com/engine/reference/commandline/run/
extract
cat ./env.list
TEST_FOO=BAR
Upvotes: 0