项目树
/backend
.env.dev
docker-compose-dev.yml
/project
我收到了以下警告信息:
docker-compose -f docker-compose-dev.yml up --build # i am in the /backend directory
WARNING: The DB_USER variable is not set. Defaulting to a blank string.
WARNING: The DB_PASSWORD variable is not set. Defaulting to a blank string.
WARNING: The DB_NAME variable is not set. Defaulting to a blank string.
这意味着Docker Compose无法看到我的环境文件。我该如何修复它?
docker-compose-dev.yml
services:
django:
build: ./project # path to Dockerfile
command: sh -c "
sleep 3 && gunicorn -w 8 --bind 0.0.0.0:8800 core_app.wsgi"
volumes:
- ./project:/project
- ./project/static:/project/static
- ./project/media:/project/media
- ./project/logs:/project/logs
expose:
- 8800
env_file:
- ./.env.dev
depends_on:
- db
db:
image: postgres:13-alpine
volumes:
- pg_data:/var/lib/postgresql/data/
expose:
- 5432
ports:
- "5435:5432"
env_file:
- ./.env.dev
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
.......
如何启用 env 文件?
附注:
数值被设置在文件 .env.dev
中。
DB_NAME=db_dev
DB_USER=postgres
DB_PASSWORD=passsss132132
ENV_TYPE=DEV
更新 发现这种方式可以使用。
docker-compose -f docker-compose-dev.yml --env-file=.env.dev up