项目树
/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文件?
P.S值在文件.env.dev
中设置
DB_NAME=db_dev
DB_USER=postgres
DB_PASSWORD=passsss132132
ENV_TYPE=DEV
UPDATE发现此方法有效
docker-compose -f docker-compose-dev.yml --env-file=.env.dev up
1条答案
按热度按时间qjp7pelc1#
如果投诉来自 docker(撰写)本身,请尝试:
1.将
./.env.dev
重新命名为.env.dev
;1.如果还没有,请将
.env.dev
重命名为.env
(默认值),并从您的组合中删除env_file
条目。[1][https://docs.docker.com/compose/env-file/](https://docs.docker.com/compose/env-file/)