The instructions in the Docker file are evaluated one at a time when you run docker build and are not reevaluated at run time.
You can still do this using a script entry point that will be evaluated at runtime after the environment variables are set.
For example, you can define the following entrypoint.sh script:
#!/bin/bash sed -i 's/CONFIG_VALUE/'"$CONFIG_VALUE"'/g' CONFIG_FILE exec " $@ "
exec " $@ " will execute any installed CMD or command.
Add it to the Docker file, for example:
COPY entrypoint.sh / RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"]
Note that if you have an existing entry point, you will need to combine it with this - you can have only one entry point.
Now you should find that the environment variable is respected ie:
docker run -e CONFIG_VALUE=100 container_name cat CONFIG_FILE
Should work as expected.
source share