Docker with Separate PostgreSQL

I see on the Docker container for Mattermost that it uses an internal PostgreSQL database. Is it possible to configure the container to use an external database?

Hi @anonymous4519576 ,

yes, you do not need to start the PostgreSQL container (small modifications to the docker-compose file will be necessary then) and in the .env file you can configure the credentials for your externally hosted database.

This is the default configuration in the .env file (it uses variables defined above, so you can still use them if you want).

MM_SQLSETTINGS_DRIVERNAME=postgres
MM_SQLSETTINGS_DATASOURCE=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable&connect_timeout=10

The hostname (postgres after the @ sign) is hardcoded, this is where you need to put the ip address or hostname of your external database server.

If you want to also skip the postgres container from being started, modify the file docker-compose.yml and remove the postgres: section as well as the dependency to it in the `mattermost:ยด section:

services:
  postgres:
    image: postgres:${POSTGRES_IMAGE_TAG}
    restart: ${RESTART_POLICY}
    security_opt:
      - no-new-privileges:true
    pids_limit: 100
    read_only: true
    tmpfs:
      - /tmp
      - /var/run/postgresql
    volumes:
      - ${POSTGRES_DATA_PATH}:/var/lib/postgresql/data
    environment:
      # timezone inside container
      - TZ

      # necessary Postgres options/variables
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB

  mattermost:
    depends_on:
      - postgres