简体   繁体   English

来自docker-compose .env文件的多个Docker构建args

[英]Multiple Docker build args from docker-compose .env file

I am experiencing an odd issue with docker-compose's .env file. 我在.env -compose的.env文件中遇到一个奇怪的问题。 I am able to use the first variable key=pair in my .env file, but only the first variable. 我可以在我的.env文件中使用第一个变量key = pair,但只能使用第一个变量。 This is my folder structure 这是我的文件夹结构

|- root
|  |- .env
|  |- docker-compose.yaml
|  |- service-1
|     |- Dockerfile

.env: .ENV:

GIT_TOKEN=c3e13c4e33935
DB_PWD=mypassword

docker-compose.yaml: 泊坞窗,compose.yaml:

version: '3'
web-server:
      container_name: service-1
      image: sdc/service-1:0.1
      build:
        context: ./service-1
        args:
          - GIT_TOKEN=$GIT_TOKEN
          - DB_PWD=$DB_PWD

service-1/Dockerfile: 服务-1 / Dockerfile:

FROM node:boron
ARG GIT_TOKEN
ARG DB_PWD
RUN git clone https://${GIT_TOKEN}@github.com/chrxn/sdc.git
RUN echo {"database_password:" $DB_PWD } > crews.txt

The problem is that the GIT_TOKEN variable is working perfectly, but the DB_PWD variable is not. 问题是GIT_TOKEN变量运行正常,但DB_PWD变量运行不正常。 Even if put the GIT_TOKEN variable in the echo line, the token is saved to a file (so I know it isn't an echo/bash interpolation issue) Any help is greatly appreciated. 即使将GIT_TOKEN变量放在回显行中,令牌也会保存到文件中(因此我知道这不是回显/ bash插值问题),我们将不胜感激。 I have read everything I can find related to Docker's environment variables. 我已经阅读了与Docker环境变量有关的所有内容。

NOTE: I've modified a few things. 注意:我已经修改了几件事。 My database password is not mypassword and that isn't a real git repo 我的数据库密码不是mypassword,也不是真正的git repo

References: 参考文献:

I really would like to stick to Docker build arguments instead of environmental variables so that the values are not stored in the container's environment variables. 我真的很想坚持使用Docker构建参数而不是环境变量,以使这些值不会存储在容器的环境变量中。

Facepalm 🤦‍♀️ - This is working perfectly. Facepalm 🤦‍♀️-效果很好。 I was putting the - DB_PWD=$DB_PWD argument under the wrong service in my docker-compose.yaml file. 我在- DB_PWD=$DB_PWD docker-compose.yaml文件- DB_PWD=$DB_PWD参数放在错误的服务下。 I will leave this here as a reference on how to use the .env file with docker build arguments -- and as a reminder to my self that I'm an idiot. 我将在这里留下有关如何在.env build参数中使用.env文件的参考-并提醒我自己我是个白痴。 I'm embarrassed --100 SOF reputation 我很尴尬--100 SOF声望

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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