Install Discourse for development using Docker

The root cause may be that pg15 modified the default authentication rules.

Configuration file path: /etc/postgresql/15/main/pg_hba.conf

File content is as follows:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::/0 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

The command executed for backup is as follows:

pg_dump --schema=public -T public.pg_* --file=‘/src/tmp/backups/default/2026-02-02-063003/dump.sql.gz’ --no-owner --no-privileges --verbose --compress=4 --username=postgres discourse_development

The command above reports an error because of the rule local all postgres peer: Peer authentication failed for user "postgres"

Solution idea: Change peer to trust to allow all local environment commands. This means no further authentication (and no password input) is required for any command.

Specific steps:

  1. Copy /etc/postgresql/15/main/pg_hba.conf from the container to local

sudo docker cp discourse_dev:/etc/postgresql/15/main/pg_hba.conf ~/discourse/data/pg_hba.conf

Grant permissions 644

sudo chmod 644 ~/discourse/data/pg_hba.conf

Modify the configuration in data/pg_hba.conf

# Database administrative login by Unix domain socket
local   all   postgres   trust
  1. Modify the d/boot_dev file to mount data/pg_hba.conf into the container, overwriting the default pg configuration file.
docker run -d \
    -p $local_publish:8025:8025 \
    -p $local_publish:3000:3000 \
    -p $local_publish:4200:4200 \
    -p $local_publish:9292:9292 \
    -p $local_publish:9405:9405 \
    -v "$DATA_DIR:/shared/postgres_data:delegated" \
    # The line below is newly added, mounting the configuration file into the container, and only giving the container read-only permission
    -v "$SOURCE_DIR/data/pg_hba.conf:/etc/postgresql/15/main/pg_hba.conf:ro" \
    -v "$SOURCE_DIR:/src:delegated" \
    -e UNICORN_BIND_ALL=true \
    $mount_plugin_symlinks \
    $ENV_ARGS \
    --hostname=discourse \
    --name=discourse_dev \
    --restart=always \
    discourse/discourse_dev:release /sbin/boot
  1. Stop and remove the current container, then rebuild the new container
d/shotdown_dev
d/boot_dev
  1. After rebuilding, start the frontend and backend applications, and test if the backup is normal
d/rails s

# Execute in another command line
d/ember-cli

On the backup page, click backup, wait a few seconds, and then view the backup file list.

1 Like

Based on the experience above, the desire to connect to the postgreSQL database in Docker using a local database client can now be realized.

Modify the configuration in the d/boot_dev file as follows:

docker run -d \
    -p $local_publish:8025:8025 \
    -p $local_publish:3000:3000 \
    -p $local_publish:4200:4200 \
    -p $local_publish:9292:9292 \
    -p $local_publish:9405:9405 \
    # Add port mapping
    -p $local_publish:55432:5432 \
    -v "$DATA_DIR:/shared/postgres_data:delegated" \
    # Keep configuration file mapping
    -v "$SOURCE_DIR/data/pg_hba.conf:/etc/postgresql/15/main/pg_hba.conf:ro" \
    -v "$SOURCE_DIR:/src:delegated" \
    -e UNICORN_BIND_ALL=true \
    $mount_plugin_symlinks \
    $ENV_ARGS \
    --hostname=discourse \
    --name=discourse_dev \
    --restart=always \
    discourse/discourse_dev:release /sbin/boot

Allow all requests to connect to pg:

In the data/pg_hba.conf file, modify the configuration as follows:

# IPv4 local connections:
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::/0 trust

Rebuild

d/shutdown_dev
d/boot_dev

Now you can connect using a local database client

I am using DBeaver here.

  1. Database port number is 55432, consistent with d/boot_dev. It is 55432 here to avoid conflicts with existing local ports.
  2. Database name
  3. It is recommended to check “Show all databases”
  4. Username
  5. Test the connection
  6. Click OK to save

Finally, I can happily view the data in the database locally.

1 Like

Is it normal that this installation does not display the menu correctly?