title: Editing the pg_hba.conf in the default postgres:12 docker image
body: <p>I'm trying to enable streaming replication in the standard postgres:12 docker image, this requires changes to <code>pg_hba.conf</code>. I've managed to update the <code>postgresql.conf</code> via forcibly making the database use it (passing the the <code>-c config_file=&quot;&lt;&gt;&quot;</code> flag in docker-compose rather through init scripts).</p>
  <p>But I cannot find a parameter or flag option to get the database to use my <code>pg_hba.conf</code> despite trying to do so in startup scripts copied to <code>docker-entrypoint-initdb.d</code>.</p>
  <p>Any ideas?</p>
  <h1>Docker-compose</h1>
  <pre class="lang-yaml prettyprint-override"><code>version: &quot;2&quot;
  services:
    postgres:
      build:
        context: ./docker
      environment:
        - POSTGRES_DB=postgres
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=postgres
      command:
        - &quot;postgres&quot;
        - &quot;-c&quot;
        - &quot;config_file=/etc/postgresql/postgresql.conf&quot;
      ports:
        - 5432:5433
  </code></pre>
  <h1>Dockerfile:</h1>
  <pre><code>FROM postgres:12
  ENV VERSION 1_0
  RUN buildDeps=&quot;curl build-essential ca-certificates git   pkg-config glib2.0 postgresql-server-dev-$PG_MAJOR&quot; \
      &amp;&amp; apt-get update \
      &amp;&amp; apt-get install -y --no-install-recommends  ${buildDeps} \
      &amp;&amp; echo &quot;deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main&quot; &gt; /etc/apt/sources.list.d/pgdg.list \
      &amp;&amp; curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
      &amp;&amp; apt-get update \
      &amp;&amp; apt-get install -y --no-install-recommends libc++1 postgresql-server-dev-$PG_MAJOR \
      &amp;&amp; mkdir -p /tmp/build \
      &amp;&amp; curl -o /tmp/build/${VERSIONN}.tar.gz -SL &quot;https://github.com/eulerto/wal2json/archive/wal2json_${VERSION}.tar.gz&quot; \
      &amp;&amp; cd /tmp/build/ \
      &amp;&amp; tar -xzf /tmp/build/${VERSIONN}.tar.gz -C /tmp/build/ \
      &amp;&amp; cd /tmp/build/wal2json-wal2json_${VERSION} \
      &amp;&amp; make &amp;&amp; make install \
      &amp;&amp; cp wal2json.so /usr/lib/postgresql/12/lib/ \
      &amp;&amp; cd / \
      &amp;&amp; rm -rf /tmp/build \
      &amp;&amp; apt-get remove -y --purge ${buildDeps} \
      &amp;&amp; apt-get autoremove -y --purge \
      &amp;&amp; rm -rf /var/lib/apt/lists/
  COPY . /
  RUN ./sql_setup.sh
  RUN mv setup.sql /docker-entrypoint-initdb.d/
  </code></pre>
  <h1>sql_setup.sh</h1>
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  set -e
  
  cat &gt; &quot;$PGDATA/server.key&quot; &lt;&lt;-EOKEY
  -----BEGIN RSA PRIVATE KEY-----
  ...
  -----END RSA PRIVATE KEY-----
  EOKEY
  chmod 0600 &quot;$PGDATA/server.key&quot;
  
  cat &gt; &quot;$PGDATA/server.crt&quot; &lt;&lt;-EOCERT
  -----BEGIN CERTIFICATE-----
  ...
  -----END CERTIFICATE-----
  EOCERT
  
  cat &lt;&lt; EOF &gt;&gt; /var/lib/postgresql/data/postgresql.conf
  port = 5433
  ssl = on
  ssl_cert_file = 'server.crt'
  ssl_key_file = 'server.key'
  max_wal_senders = 1
  max_replication_slots = 1
  wal_level = logical
  shared_preload_libraries = wal2json
  EOF
  
  cat &lt;&lt; EOF &gt;&gt; /var/lib/postgresql/data/pg_hba.conf
  # TYPE  DATABASE        USER            ADDRESS                 METHOD
  host    all             pass_user       0.0.0.0/0            password
  host    all             md5_user        0.0.0.0/0            md5
  host    all             scram_user      0.0.0.0/0            scram-sha-256
  host    all             pass_user       ::0/0                password
  host    all             md5_user        ::0/0                md5
  host    all             scram_user      ::0/0                scram-sha-256
  
  hostssl all             ssl_user        0.0.0.0/0            trust
  hostssl all             ssl_user        ::0/0                trust
  host    all             ssl_user        0.0.0.0/0            reject
  host    all             ssl_user        ::0/0                reject
  
  # IPv4 local connections:
  host    all             postgres        0.0.0.0/0            trust
  # IPv6 local connections:
  host    all             postgres        ::0/0                trust
  # Unix socket connections:
  local   all             postgres                             trust
  # Enable streaming replication with wal2json:
  host    replication     all             127.0.0.1/32         trust
  EOF
  </code></pre>
  <h1>setup.sql</h1>
  <pre class="lang-sql prettyprint-override"><code>CREATE ROLE pass_user PASSWORD 'password' LOGIN;
  CREATE ROLE md5_user PASSWORD 'password' LOGIN;
  SET password_encryption TO 'scram-sha-256';
  CREATE ROLE scram_user PASSWORD 'password' LOGIN;
  CREATE ROLE ssl_user LOGIN;
  CREATE EXTENSION hstore;
  CREATE EXTENSION citext;
  </code></pre>