Jasmine Lognnes
Jasmine Lognnes

Reputation: 7097

Making a variable available between containers?

When I read the Docker docs, I get the impression that it is possible make a variable from one container available in another container when using Docker Compose.

So in container A I do in a script

export PASS=abc

and in the docker-compose.yml

containera:
  image: ...
  environment:
    - PASS

containerb:
  build: ...
  links:
    - containera:ca

But when I do env in container B, then PASS is empty.

Question

How do I make the generated value of PASS in container A available in container B?

Upvotes: 1

Views: 1208

Answers (1)

Will Stern
Will Stern

Reputation: 17579

Docker only shares environment variables originating from Docker. see their docs here

Since your value is generated by a process running in containera, Docker has no awareness of its value.

You would either need to:

  • set a static value in Dockerfile/docker-compose.yml
  • set a static ENV variable with a port/endpoint for accessing a service inside containera that would return the generated password/token.

Upvotes: 1

Related Questions