# Docker with Separate PostgreSQL

**URL:** <https://forum.mattermost.com/t/docker-with-separate-postgresql/15597>\
**Category:** Troubleshooting\
**Created:** [April 6, 2023, 2:17am UTC](https://forum.mattermost.com/t/docker-with-separate-postgresql/15597 "2023-04-06T02:17:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous4519576](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@anonymous4519576](https://forum.mattermost.com/u/anonymous4519576)\
**Post date:** [April 6, 2023, 2:17am UTC](https://forum.mattermost.com/t/docker-with-separate-postgresql/15597/1 "2023-04-06T02:17:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [April 6, 2023, 3:54am UTC](https://forum.mattermost.com/t/docker-with-separate-postgresql/15597/2 "2023-04-06T03:54:54Z")

</div>

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).

```auto
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:

```yaml
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

```
