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

Most upvoted comments

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:

ARG NODE=production
ENV NODE_ENV ${NODE}
RUN npm start

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 of PATH_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"'
  • modify your dockerfile
FROM baseimage

ARG PATH_PREFIX                            # declare PATH_PREFIX as build arg
RUN PATH_PREFIX=${PATH_PREFIX} ./dobuild   # use PATH_PREFIX (in this case via environment variable)