https://pantsbuild.org/ logo
#general
Title
# general
b

bitter-ability-32190

07/27/2022, 2:21 PM
I think I'm missing something, but couldn't grok this from the docs. How can I get env vars propagated to
./pants run <docker_img>
? I've tried `--docker-env-vars="MYVAR"`:
MYVAR=1 ./pants --docker-env-vars="MYVAR" run <docker>
, but the
pex_binary
which is run is no dice. I suspect maybe
docker.run_args
?
Ah
-e
on
docker.run_args
should do it, but I get
"docker run" requires at least 1 argument.
🤔 I'm using
--docker-run-args="-e"
so it should be _append_ing a value
Oh you need a
-e
and then the name 🤦‍♂️
@happy-kitchen-89482 here's another case of default
run_args
on a
docker_image
target would be nice
👀 1
I'll open a ticket
c

clean-alligator-41449

09/19/2023, 8:45 AM
Can you help me understand why setting --docker-env-vars="[\"MYARG\"]" does not propagate the MYARG, but docker-run-args="-e MYARG" does? I was very confused why the env variables didn't show up until I saw this post.
b

bitter-ability-32190

09/19/2023, 11:12 AM
IIUC, The first one propagates the environment variable to the docker-related processes (so Pants is providing the environment variable). The second one is telling docker itself to grab the env var from environment. Put another way, the first makes sure the variable is in the sandbox, the second is telling docker to use it
c

clean-alligator-41449

09/19/2023, 1:16 PM
Copy code
Put another way, the first makes sure the variable is in the sandbox, the second is telling docker to use it
But the variable does not have to be in the sandbox, for docker to pick it up when doing
pants run
on a docker image target. I guess it's not obvious to me why a pants run on a docker image (which leads to a
docker run
command, does not count as an invocation. According to the docs
Environment variables to set for docker invocations.
I have what I need now, but I would humbly suggest that maybe the documentation could have been clarified.
b

bitter-ability-32190

09/19/2023, 1:17 PM
Admittedly this is a year old thread so my remembering of the details is likely weathered 😅
c

clean-alligator-41449

09/19/2023, 1:18 PM
Totally understandable, but you gave me all the help I needed. Thanks a lot:)
b

bitter-ability-32190

09/19/2023, 1:19 PM
Well glad for that. 🙂 Pass it on!
5 Views