Using Circleci context in a service container

some-job:
  docker:
    - image: python
    - image: some-proxy
      command: ["-password:$SOME_VAR_FROM_CONTEXT"]

In this example, SOME_VAR_FROM_CONTEXT is a variable I have defined in my context.

It appears that SOME_VAR_FROM_CONTEXT is not available in my service container. Only my primary container. How would I pass this in?

I believe you need to enable contexts in your workflow, see point (4) here:

https://circleci.com/docs/2.0/contexts/

THanks @halfer, I’m not sure I understand

In my script of the primary container I do have access to the context:

some-job:
  docker:
    - image: python
    - image: some-proxy
      command: ["-password:$SOME_VAR_FROM_CONTEXT"] # << does not work
  steps:
    - run: echo "$SOME_VAR_FROM_CONTEXT" # << works

Could you try enabling it with the context key, in case that helps? See the YAML example in the link I gave.

It is also possible, however, that you have found a place where environment variables do not work - the command section of a secondary image is run on a remote Docker server, so might be treated differently.

I have a similar problem.

The desire is to use the docker executor with N containers and build contexts, with the build context ENVs available to all containers; not just the ‘primary’ container in which all steps invoke.

Example:

executors:
  marktest:
    docker:
      - image: testing-suite-app
        auth:
          username: $FOO
          password: $BAR
        environment:
          TOP_SECRET_FROM_CONTEXT: $BAZ
      - image: app-to-test
        auth:
          username: $FOO
          password: $BAR
        environment:
          TOP_SECRET_FROM_CONTEXT_NEEDED_TO_BOOT: $STUFF
	  - image: whatever
		  ...
		  
marktest:
  executor: marktest
	steps:
	  - run:
            name: Do Something
            command: [ ... trigger test suite... ]

In this above example, only values explicitly set in the environment key of the docker executor are being set, with those N service containers having no access to the envs in the build context nor the project contexts.

Is there any way to get the build contexts (or any envs from any level of circle) available in a given service container for the docker executor OTHER then explicitly adding them line-by-line into the ‘environment:’ key of the executor section of EACH service container?

Something like this would be ideal:

executors:
  marktest:
    docker:
      - image: testing-suite-app
        auth:
          username: $FOO
          password: $BAR
        environment:
          TOP_SECRET_FROM_CONTEXT: $BAZ
      - image: app-to-test
        auth:
          username: $FOO
          password: $BAR
       context:
         - my_build_context
        environment:
          TOP_SECRET_FROM_CONTEXT_NEEDED_TO_BOOT: $STUFF
...