1

I'm developing an application that creates a container and runs it, using a docker image.

I create the client using this snippet:
client = docker.DockerClient(base_url='unix://var/run/docker.sock', version='1.41', timeout=10)
and it's fine. I instantiate and run the image properly using this:
client.containers.run(image=deployment_json['container_image'], command="sbt run", environment=cfg) The environment parameter does not lead into error, and the container runs fine, but the image doesn't retrieve the environment variable (NullPointer, it's a Scala app) the cfg is created like this: cfg = ['var_name', str(env)] where env is a json object.

Using docker lib version 5.0.0.
What am I missing? How do i give environment variables to docker images?

2
  • What does env contain? Commented May 11, 2021 at 7:43
  • it's a json... in the scala app, i retrieve this json as a string and then treat it... Commented May 11, 2021 at 7:47

1 Answer 1

1

From docker cli perspective you have --env , -e flag to set environment variables when running docker run

From docs I think this can be achieved using environment var:


exec_run(cmd, stdout=True, stderr=True, stdin=False, tty=False, privileged=False, user='', detach=False, stream=False, socket=False, environment=None, workdir=None, demux=False)

where you should pass as an argument the environment variable

environment (dict or list) – Environment variables to set inside the container, as a dictionary or a list of strings in the format ["SOMEVARIABLE=xxx"].

Sign up to request clarification or add additional context in comments.

6 Comments

exactly what i did, if you would read. but thank you for the effort
maybe i created the dict the wrong way, wait
Yes sorry I've missed it, I think cfg = ['var_name', str(env)] does not look ok it should be more like this ["SOMEVARIABLE=xxx"]
exactly. my fault of course.. I'll mark your answer as useful, but not as solution if you'd like
Sure man, I just wanted to help I'm not a reputation hunter .
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.