我如何使用docker-compose添加一个带有yaml配置的文件夹到docker?

ubby3x7f  于 2023-01-16  发布在  Docker
关注(0)|答案(1)|浏览(166)

我有一个项目结构:

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
如何解决这一问题?

tp5buhyn

tp5buhyn1#

你需要把volumes指令放在一个服务里面,大概是这样的:

app:
        build: 
          context: ./server/app
          dockerfile: Dockerfile
        env_file:
            - local.env
        environment:
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres
            - POSTGRES_DB=devdb
        volumes:
            - ./configs:/configs

如果多个容器需要它,您必须在多个服务中重复它。

相关问题