Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I add a folder with yaml configuration to docker using docker-compose?

I have a project structure:

configs
   -config.yaml
server
...
docker-compose.yaml

the docker file is :

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:
        

The app uses config.yml and I’m wondering how to add the configs folder to the container? I tried to do this :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

volumes:
      - /configs:/configs

but it gives me services.volumes must be a mapping.

How can this be resolved?

>Solution :

You need to put volumes directive inside a service. Probably something like this:

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

If multiple containers need it you’ll have to repeat it in multiple services.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading