dokku: ENV variables not available at build time for Dockerfile deploys
The docs say “The variables are available both at run time and during the application build/compilation step.” but I’ve not seen this actually happen at build time.
actual app config:
$ ssh dokku@test config adminapp
=====> adminapp config vars
API_BASE: //adminapp-api.test.zipwhip.com
DOKKU_APP_RESTORE: 1
DOKKU_DOCKERFILE_PORT: 80
DOKKU_NGINX_PORT: 80
NODE_ENV: production
PATH_PREFIX: /admin
I’m logging from my build script, so at build time I see:
Step 1 : RUN NODE_ENV=production webpack -p
---> Running in 0826574bc4e0
===> Building with NODE_ENV 'production'
===> Building with PATH_PREFIX 'undefined'
===> Building with API_BASE 'undefined'
Hash: 54683fe2b93e4d330eed
Version: webpack 1.12.11
Time: 170802ms
...
The NODE_ENV
var is only set because I prefixed the Dockerfile build step with NODE_ENV=production
while the other vars I expect to be set (PATH_PREFIX
and API_BASE
) are still undefined
.
This is with dokku version 0.4.7
$ ssh dokku@test version
0.4.7
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 36 (22 by maintainers)
Commits related to this issue
- Document when configuration variables are available. Closes #1860 [ci skip] — committed to dokku/dokku by josegonzalez 8 years ago
- Merge pull request #2007 from dokku/josegonzalez-patch-1 Document when configuration variables are available. Closes #1860 — committed to dokku/dokku by josegonzalez 8 years ago
- docs: Add documentation around adding build-time configuration variables Refs #2776 Closes #1860 [ci skip] — committed to dokku/dokku by josegonzalez 7 years ago
Just for clarification: the correct command is
dokku docker-options:add myapp build '--build-arg "PATH_PREFIX=/myapp"'
(docker-options
vs.build-options
)After hours trying to make it work… Work for me in this way:
dokku docker-options:add myapp build ‘–build-arg NODE_ENV=production’
dockerfile
ARG NODE_ENV=production ENV NODE_ENV ${NODE_ENV} RUN echo $NODE_ENV
Use ARG for default value even you don’t need.
Hopeful that helps someone. #2776
For anyone running into issues passing NODE_ENV as a build-arg…try just passing it as NODE instead, such as:
docker build --build-arg NODE=development --rm -t some/name .
and in Dockerfile:
For anybody running into this problem:
dokku docker-options:add myapp build '--build-arg "PATH_PREFIX=/myapp"'
was creating a build arg
"PATH_PREFIX
instead ofPATH_PREFIX
. This took me a long time to realize.I wrote something up about how I solved the problem of build args: http://craigbeck.io/blog/2016/01/13/dokku-plus-dockerfile-deployments/
dokku build-options:add myapp build '--build-arg "PATH_PREFIX=/myapp"'