P
P
PtrGrd2021-11-13 13:23:22
Docker
PtrGrd, 2021-11-13 13:23:22

How to mount config file in docker-compose?

I need to move two files outside of Docker so that when they change on the host, I don’t need to rebuild the image once again. Tried through volume, with binds, all to no avail. I make changes to the configuration file (settings.json and text.txt) -> I reload the container and still there are no changes. Help me please. Thank you in advance.

docker-compose.yml

version: '3.7'

services:
 script:
  build: ./script/
  command: /script/src/script.py
  container_name: script-mtg
  depends_on:
    - db
  volumes:
    - ./script/src/settings.json:/usr/content/src/settings.json
    - ./script/res/text.txt:/usr/content/res/text.txt
 db:
  image: postgres:latest
  container_name: dbpg-mtg
  restart: always
  environment:
    - POSTGRES_DB=users
    - POSTGRES_USER=postgres
    - POSTGRES_PASSWORD=postgres
  volumes:
    - ./ .database/postgres/data:/var/lib/postgresql/data
  ports:
    - "5432"


Project Structure
.
├── docker-compose.yml
└── script
    ├── Dockerfile
    ├── requirements.txt
    ├── res
    │   ├── text.txt
    └── src
        ├── config.ini
        ├── main.session
        ├── script.py
        └── settings.json

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-11-13
@PtrGrd

Why is the path to the config in the container /usr/content/src/settings.json?
After all, you run the script from the directory /script/src/
Try:

- ./script/src/settings.json:/script/src/settings.json
- ./script/res/text.txt:/script/res/text.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question