ksclfanatic
ksclfanatic

Reputation: 142

docker environment variables aren't replaced

I created a Dockerfile, which is based on the freeradius server image. Locally I have a folder called raddb containing configuration files.

This setup needs to be installed at multiple places with all configuration parameters the same, exceptionally 2 things, an IP address and a password secret. I want to do this with environment variables so I executed following command to start up my docker container:

docker run -e SECRET=password123 -e IP=127.0.0.1  -p 1812-1813:1812-1813/udp radius -X

This is my Dockerfile

FROM freeradius/freeradius-server:latest

COPY raddb/ /etc/raddb/

RUN sed -i "s|<SECRET>|$SECRET|g" /etc/raddb/clients.conf
RUN sed -i "s|<IP>|$IP|g" /etc/raddb/clients.conf

With the 2 sed commands I want to replace my parameter placeholder with the environment variable value.

However when I start up my docker container, these are empty.

I guess this comes because the sed commands are ran during the docker build and at that point the environment variables have no value, so that's probably why.

How do I fix this properly?

Upvotes: 1

Views: 535

Answers (1)

Julian
Julian

Reputation: 2822

The sed commands are executed while building the image before the envs are set in docker run. You can execute a script when the container is started with CMD and change the files there. Only the last CMD is used so you have to call the original command (freeradius) at the end of the script.

Upvotes: 1

Related Questions