Docker compose完全忽略了我的包含环境变量的文件



这是我的docker-compose.yml文件

version: "3.8"
services:
app:
build:
context: .
dockerfile: Dockerfile.dev
# environment:
#   - REDIS_URL=redis://redis:6379/0
env_file: .env
user: 1000:1000
depends_on:
#   - database
- redis
ports:
- "80:80"
volumes:
- .:/home/ubuntu/myapp
# - gem_cache:/usr/local/bundle/gems
# - node_modules:/app/node_modules
command: "tail -f /dev/null"
redis:
image: redis:latest
volumes:
# gem_cache:
db_data:
# node_modules:

这是我的.env文件:

REDIS_URL=redis://redis:6379/0
BUNDLE_GEMS__CONTRIBSYS__COM=XYZ:XYZ

这是我的Dockerfile的开始

FROM ruby:2.5.8-buster
ARG BUNDLE_GEMS__CONTRIBSYS__COM
RUN echo "Gem creds: $BUNDLE_GEMS__CONTRIBSYS__COM"

不管出于什么原因,我的Dockerfile没有被传递来自docker-compose.yml的参数。正如你在下面看到的,当我只是简单地告诉它回声时,结果是空的:

redis uses an image, skipping
Building app
Sending build context to Docker daemon  631.2MB
Step 1/16 : FROM ruby:2.5.8-buster
---> fc5e02c64ca4
Step 2/16 : ARG BUNDLE_GEMS__CONTRIBSYS__COM
---> Using cache
---> 2f1b8ded699d
Step 3/16 : RUN echo "Gem creds: $BUNDLE_GEMS__CONTRIBSYS__COM"
---> Running in 0b28870daba6
Gem creds: 
Removing intermediate container 0b28870daba6
---> 85236c218d7f
Step 4/16 : RUN groupadd --gid 1000 ubuntu
---> Running in 0eb5e328ff78
Removing intermediate container 0eb5e328ff78
---> 5cee9eafed20
Step 5/16 : RUN adduser --disabled-password --gecos '' --uid 1000 --gid 1000 ubuntu
---> Running in 02ba757cd414
^CERROR: Aborting.

为什么会发生这种情况?

你能试着在你的docker compose文件中给出args吗?

services:
app:
build:
context: .
dockerfile: Dockerfile.dev
args:
BUNDLE_GEMS__CONTRIBSYS__COM=$BUNDLE_GEMS__CONTRIBSYS__COM

See, docker documentation:
https://docs.docker.com/compose/compose-file/compose-file-v3/#args

相关内容

  • 没有找到相关文章

最新更新