0

I'm currently trying to use variable substitution in a docker-compse.yml file. This file contains the following:

jenkins:
  image: "jenkins:${JENKINS_VERSION}"
  external_links:
      - mongodb:mongo
  ports:
    - 8000:8080

The image below shows what happens when I try to start everything up.

Docker compose variable not set

As you can see, docker-compose shows a warning saying that the variable is not set. I suspect this is caused due to the use of sudo to start docker-compose. My setup (a Jenkins docker container which has access to docker and docker-compose via volume mounts) currently requires the use of sudo. Would it be better to stop docker requiring sudo, or is there another way to fix this without changing the current setup?

2
  • try adding docker to your user group, so that you don t have to use sudo again and again. Also logout and login again in your user group to make it working. Commented Feb 29, 2016 at 21:34
  • You could set the var in a script and then launch compose from the script passing it the var Commented Feb 29, 2016 at 22:19

1 Answer 1

1

sudo -E preserve the user environment when running the command. It should do what you want.

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

4 Comments

This works! To clarify, I use the following command to make it work: JENKINS_VERSION=123 sudo -E docker-compose up
I'm wondering if there is a way to do this with multiple variables? JENKINS_VERSION=123 && JENKINS_TEST=456 sudo -E docker-compose up is not working (obviously) and I don't like adding variables to a sudoers file or something like that.
Found it! export JENKINS_VERSION=123 && export JENKINS_TEST=456 && sudo -E docker-compose up
I think you can just leave them space delimited and it will work JENKINS_VERSION=123 JENKINS_TEST=456 sudo -E docker-compose up

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.