What is the recommendation for using esc to inject...
# esc
r
What is the recommendation for using esc to inject environment variables with
docker run
locally?
g
Can you give me an example of what you’re trying to do?
r
Copy code
docker run -e DATABASE_HOST=$DATABASE_HOST -e DATABASE_PASSWORD=$DATABASE_PASSWORD -e DATABASE_USERNAME=$DATABASE_USERNAME -e OPENAI_API_KEY=$OPENAI_API_KEY -e TURBOPUFFER_API_KEY=$TURBOPUFFER_API_KEY -p 3001:3001 cortex-api
Ended up just writing a bash script that invokes pulumi env run and that shell script. Would basically like an easy way to project all environment variables from an env into a docker run command.
also, 👋 😄
g
👋 😁
I think
esc run <env> -- docker run -e ...
would do the trick. That should set your env var context, so you could reference it in the docker command.
But I agree that an integration to set them automatically could be useful
r
That is basically what I did, but I have to specify each env var individually. There are many, so I wrote a bash script. But every time I add an env var to the environment, I need to update the bash script. Kind of a pain.
g
It looks like you could simplify the usage in a couple ways: 1. You don’t have to duplicate the key=value on the command line.
docker run -e DATABASE_HOST
rather than
-e DATABASE_HOST=$DATABASE_HOST
. 2. You could use the `files` support to create an
env-file
.
Here’s a one-liner that dynamically sets environment variables in a docker container:
Copy code
esc run -i pulumi/docker-env-test -- sh -c 'docker run --rm -it --env-file=$DOCKER_ENVFILE alpine:latest /bin/sh'
/ # env
HOSTNAME=8c22fa56a306
SHLVL=1
HOME=/root
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
FOO=bar
PWD=/
/ #
Environment definition:
Copy code
values:
  files:
    DOCKER_ENVFILE: |
      FOO=bar
r
👍 would make a great docs page
g
Working on it 😄