https://pulumi.com logo
#general
Title
# general
f

flat-engine-80045

04/16/2020, 10:54 PM
Hi all. With the pulumi_docker library for python, how do I declare env vars for a container?
envs
is of type pulumi.Input[list] but i would expect it to be of type pulumi.Input[dict] to take key:value pairs for the env vars? I appreciate any help
r

red-match-15116

04/16/2020, 11:42 PM
You can pass them in like
envs = ["KEY=value", "KEY2=value2"]
f

flat-engine-80045

04/17/2020, 12:02 AM
Thank you so much! Maybe you can answer another question (or i can throw it back in the channel). When trying to create a simple docker container with the following code, subsequent pulumi up's always show a diff and therefore recreate containers. is this expected behavior?
Copy code
container = docker.Container(resource_name="container", image="containous/whoami",)
Results in
Copy code
~ image: "sha256:0f6fbbedd3777530ea3bedadf0a75b9aba805a55f6c5481ef0ebd762c5eeb818" => "containous/whoami"
r

red-match-15116

04/17/2020, 12:43 AM
This is expected behavior. Pulumi can't be certain of a safe "update" to the container, it makes more sense to create a new container that matches your desired configuration and replace it rather than risk updating an existing resource. The sha you see is the immutable identifier for that specific version of the image (also known as a digest), whereas pulling it by the name "containous/whoami" doesn't guarantee that the underlying container hasn't been updated in some way, and pulumi doesn't know that the underlying version hasn't changed between your deploys. If you instead do
Copy code
container = docker.Container(resource_name="container", image="sha256:0f6fbbedd3777530ea3bedadf0a75b9aba805a55f6c5481ef0ebd762c5eeb818")
pulumi is now certain that there is nothing different between the image you are asking for and the one that you have in state, and so you won't see a change and replacement.
Copy code
Updating (dev):
     Type                 Name               Status     
     pulumi:pulumi:Stack  docker-python-dev             
 
Outputs:
    image: "sha256:0f6fbbedd3777530ea3bedadf0a75b9aba805a55f6c5481ef0ebd762c5eeb818"

Resources:
    2 unchanged

Duration: 1s
🔍 1
f

flat-engine-80045

04/17/2020, 4:47 PM
Ok got it. Thank you so much for your time and help!
👍 1
2 Views