I am experiencing an odd issue with docker-compose's .env
file. I am able to use the first variable key=pair in my .env file, but only the first variable. This is my folder structure
|- root
| |- .env
| |- docker-compose.yaml
| |- service-1
| |- Dockerfile
.env:
GIT_TOKEN=c3e13c4e33935
DB_PWD=mypassword
docker-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:
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. 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. I have read everything I can find related to Docker's environment variables.
NOTE: I've modified a few things. My database password is not mypassword and that isn't a real git repo
References:
- .env file
- ARG
- Similar example but setting container environment variables
- False issue raised because .env and env_file is so confusing
- combine ARG and ENV
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.