1

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

1 Answer 1

1

The following works fine:

    command: postgres -c config_file='/etc/postgresql/postgres.conf' -c 'hba_file=/etc/postgresql/pg_hba.conf'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.