Rob Rob - 10 months ago 82
Node.js Question

Docker environment variables, dokku-redis

Using redis as my session store in my express.js app. I'm having problems. Narrowed them down to a connection issue.

How do I access a docker environment variable from within an express.js app? I'm using dokku-redis.

It reports that environment variables are automatically set up on the linked app... I've linked my app. running dokku redis:info foo shows that all is linked. I'm trying to pull in REDIS_URL

Thanks, Rob

a redis service can be linked to a
container this will use native docker
links via the docker-options plugin
here we link it to our 'playground' app
NOTE: this will restart your app
dokku redis:link lolipop playground

the following environment variables will be set automatically by docker (not on the app itself, so they won’t be listed when calling dokku config)


and the following will be set on the linked application by default


NOTE: the host exposed here only works internally in docker containers. If
you want your container to be reachable from outside, you should use 'expose'.


Edit - sorry, I forgot to add that I have tried process.env

Answer Source

How did you link the redis service with your application? You cannot simply do dokku config:set, and if you did, you should unset it and then use dokku redis:link instead. Once you do that, rebuild your app using dokku ps:rebuild APP and you should get process.env.REDIS_URL set.