我有一个项目结构:
configs
-config.yaml
server
...
docker-compose.yaml
docker文件是:
version: '3.8'
services:
volumes:
- /configs:/configs
postgres:
image: postgres:12
restart: always
ports:
- '5432:5432'
volumes:
- ./db_data:/var/lib/postgresql/data
- ./server/scripts/init.sql:/docker-entrypoint-initdb.d/create_tables.sql
env_file:
- local.env
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "devdb", "-U","postgres" ]
timeout: 45s
interval: 10s
retries: 10
app:
build:
context: ./server/app
dockerfile: Dockerfile
env_file:
- local.env
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=devdb
volumes:
configs:
应用使用config.yml
,我想知道如何将configs文件夹添加到容器中?我尝试这样做:
volumes:
- /configs:/configs
但它给出了services.volumes must be a mapping
。
如何解决这一问题?
1条答案
按热度按时间tp5buhyn1#
你需要把
volumes
指令放在一个服务里面,大概是这样的:如果多个容器需要它,您必须在多个服务中重复它。