In Dockerfile, I upload one configuration file from curl, which I then need to edit a little, here is an example structure:

  - type: http
    port: 8989
    # for security reasons bind to localhost
    bindHost: localhost
      appenders: []
  - type: http
    port: 8990
    bindHost: localhost

I need to edit both bindHost parameters, it would be desirable if I could pass their values as a parameter during docker build, but I didn’t seem to find anything on the Internet or in the documentation.


If I understood the question right, in your Dockerfile command, pipe your curl to a sed:

curl XXX | sed -e "s/bindHost: localhost/bindHost: ${your_variable}/g" > yourfile.yaml

Or you can edit your file after it was been downloaded:

sed -ie "s/bindHost: localhost/bindHost: ${your_variable}/g" /path/to/your/file

You can pass values to your Dockerfile with '--build-arg', and use that value in a RUN sed call, for instance to inject an IP address parameter:

FROM whatever

COPY config.file /etc/config.file
RUN sed -i -r "s/#IPADDR#/$IPADDR/g" /etc/config.file

And you build with:

docker build -t foobar --build-arg IPADDR= .

You can also convert the build arguments into runtime environment variables:


which would be nicer if your config syntax can perform a substitution of variables from the environment (no need to run sed).

But this makes the image a bit too cast in concrete, you can instead set the environment variables when you start the container (docker run with --env, --env-list) and use these values to edit the config file on-the-fly in a script that is the container entry point, unless of course your config syntax (or start parameters) can do the envvar substitution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.