简体   繁体   中英

Postgres in docker-compose can't find/mount /etc/postgresql/postgres.conf

I'm trying to mount my postgres.conf and pg_hba.conf using docker-compose and having difficulty understanding why it work when run using docker-cli and doesn't with docker-compose

The following docker-compose causes the image to crash with error:

/usr/local/bin/docker-entrypoint.sh: line 176: /config_file=/etc/postgresql/postgres.conf: No such file or directory

docker-compose.yml


services:
  postgres-master:
    image: postgres:11.4
    container_name: postgres-master
    volumes:
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
      - /home/agilob/dockers/pg/data:/var/lib/postgresql/data:rw
      - $PWD/pg:/etc/postgresql:rw
      - /etc/localtime:/etc/localtime:ro
    hostname: 'primary'
    environment:
      - PGHOST=/tmp
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
      - MAX_CONNECTIONS=10
      - MAX_WAL_SENDERS=5
      - PG_MODE=primary
      - PUID=1000
      - PGID=1000
    ports:
      - "5432:5432"
    command: 'config_file=/etc/postgresql/postgres.conf hba_file=/etc/postgresql/pg_hba.conf'

This command works fine:

docker run -d --name some-postgres -v "$PWD/postgres.conf":/etc/postgresql/postgresql.conf postgres -c 'config_file=/etc/postgresql/postgresql.conf'

also when I remove command: section and run the same docker-compose:

$ docker-compose -f postgres-compose.yml up -d 
Recreating postgres-master ... done
$ docker exec -it postgres-master bash
root@primary:/# cd /etc/postgresql
root@primary:/etc/postgresql# ls
pg_hba.conf  postgres.conf

The files are present in /etc/postgres.

Files in $PWD/pg are present:

$ ls pg
pg_hba.conf  postgres.conf

以下工作正常:

    command: postgres -c config_file='/etc/postgresql/postgres.conf' -c 'hba_file=/etc/postgresql/pg_hba.conf'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM