Use Dokku Environment variables in DockerFile

1.5k views Asked by At

I'm tring to use Dokku Environment variables in DockerFile but with no success.

Dokku Env is set with:

dokku config:set www NR_APP=AppName

In DockerFile, i would like to put this NR_APP to a file with:

RUN sh -c 'echo "newrelic.appname=\"$NR_APP\"" >> /etc/php5/apache2/conf.d/newrelic.ini'

But it doesn't work, the result in file is:

newrelic.appname=

If i try to echo only ENV during build with:

RUN echo "$NR_APP"

It returns blank.

If i try to set NR_APP inside DockerFile with:

ENV NR_APP AppName

It works, but i don't want to define it inside DockerFile because it's a value that changes based on develop/production deployment and i've to do it also with license_key.

Thanks!

1

There are 1 answers

2
Adrian Mouat On BEST ANSWER

I've never used Dokku, but you will only be able to use those variables at run-time in a launched container.

Docker intentionally doesn't allow you to pass in variables to docker build, so that builds are reproducible across environments.

I suspect you can just write a script that configures the application at run-time using the given variables and then launches it. Just reference this script from the ENTRYPOINT or CMD instruction in the Dockerfile.