简体   繁体   中英

Variable substitution in docker-compose.yml file when running docker-compose with sudo

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组合变量未设置

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM