# Use nginx-proxy and v3.7.1 (Docker)

**URL:** <https://forum.mattermost.com/t/use-nginx-proxy-and-v3-7-1-docker/3062>\
**Category:** Installation\
**Created:** [March 20, 2017, 8:51am UTC](https://forum.mattermost.com/t/use-nginx-proxy-and-v3-7-1-docker/3062 "2017-03-20T08:51:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fuerst](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/fuerst/32/1185_2.png) [@fuerst](https://forum.mattermost.com/u/fuerst)\
**Post date:** [March 20, 2017, 8:51am UTC](https://forum.mattermost.com/t/use-nginx-proxy-and-v3-7-1-docker/3062/1 "2017-03-20T08:51:39Z")

</div>

Just want to describe my setup to run Mattermost using the Docker setup together with [nginx-proxy](https://github.com/jwilder/nginx-proxy) in front of Mattermost. Since v3.7.1 the Mattermost Docker setup creates it’s own network for communication between containers. nginx-proxy needs to know about this network. That means you need to find the network and connect it to nginx-proxy:

```auto
docker network ls
# Grep the name of your Mattermost network like "mymattermost_default".
docker network connect mymattermost_default nginx-proxy

```

Now restart the Mattermost _app_ container (or _web_ if using it) to get nginx-proxy configured correctly:

```auto
docker-compose stop app
docker-compose start app

```

BTW: With nginx-proxy there is no need to run the _web_ container. My docker-compose.yml looks like this:

```auto
version: "2"

services:

  db:
    build: db
    restart: unless-stopped
    volumes:
      - ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - POSTGRES_USER=mmuser
      - POSTGRES_PASSWORD=mmuser_password
      - POSTGRES_DB=mattermost
    # uncomment the following to enable backup
    # - AWS_ACCESS_KEY_ID=XXXX
    # - AWS_SECRET_ACCESS_KEY=XXXX
    # - WALE_S3_PREFIX=s3://BUCKET_NAME/PATH
    # - AWS_REGION=us-east-1
    # in case your config is not in default location
    # - MM_CONFIG=/mattermost/config/config.jso

  app:
    build:
      context: app
      # comment out for team edition
      #dockerfile: Dockerfile-enterprise
    restart: unless-stopped
    volumes:
      - ./volumes/app/mattermost/config:/mattermost/config:rw
      - ./volumes/app/mattermost/data:/mattermost/data:rw
      - ./volumes/app/mattermost/logs:/mattermost/logs:rw
      - /etc/localtime:/etc/localtime:ro
    environment:
      # set same as db credentials and dbname
      - MM_USERNAME=mmuser
      - MM_PASSWORD=mmuser_password
      - MM_DBNAME=mattermost
      - VIRTUAL_HOST=mymattermost.tld
      - LETSENCRYPT_HOST=mymattermost.tld
      - LETSENCRYPT_EMAIL=me@mymattermost.tld
    expose:
     - "80"
    depends_on:
      - db

```

Notes:

- Important changes are the VIRTUAL\_HOST environment variable and the _expose_ directive which tells nginx-proxy where to connect to the Mattermost backend.
- I’m using the [LetsEncrypt companion container for nginx-proxy](https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion) for automatic Let’s Encrypt certs.
- You may customize the nginx-proxy settings as described at their Github page (can not post the link because as new user to this forum I’m not allowed to post mor than 2 links). For instance the Mattermost nginx is configured with `client_max_body_size 50M;`.
- The network needs to be connected manually this way. To automatize this you may create a independent network before and use it together with nginx-proxy. See docker-compose documentation regarding using external networks.

---

<div class="post-metadata">

**Author:** ![compass](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/compass/32/1054_2.png) [@compass](https://forum.mattermost.com/u/compass)\
**Post date:** [March 23, 2017, 7:28pm UTC](https://forum.mattermost.com/t/use-nginx-proxy-and-v3-7-1-docker/3062/2 "2017-03-23T19:28:04Z")

</div>

Thanks @fuerst for the tips. Since you are changing the docker-compose file, would you replace the web container image with your nginx-proxy so that you don’t need the steps to figure out the network. Also if you want, you can also use custom network, for which you can use your own network name ([https://docs.docker.com/compose/networking/#specifying-custom-networks](https://docs.docker.com/compose/networking/#specifying-custom-networks)). Then connect nginx-proxy to the known network.

---

<div class="post-metadata">

**Author:** ![fuerst](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/fuerst/32/1185_2.png) [@fuerst](https://forum.mattermost.com/u/fuerst)\
**Post date:** [March 24, 2017, 1:07pm UTC](https://forum.mattermost.com/t/use-nginx-proxy-and-v3-7-1-docker/3062/3 "2017-03-24T13:07:57Z")

</div>

The nginx-proxy is playing proxy for many containers at the host so I don’t want tight coupling to Mattermost. I rather look for an option to let the nginx-proxy container know: Hey, there is a mattermost container starting. Please use its network to connect to it.

---

<div class="post-metadata">

**Author:** ![kaeru](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/kaeru/32/1449_2.png) [@kaeru](https://forum.mattermost.com/u/kaeru)\
**Post date:** [August 10, 2017, 2:56pm UTC](https://forum.mattermost.com/t/use-nginx-proxy-and-v3-7-1-docker/3062/4 "2017-08-10T14:56:21Z")

</div>

This was super helpful for me to get things up and running.

I had to make one minor addition to get HTTPS to work, which was to expose port 443 as well. So my `docker-compose.yml` looks like this:

```auto
version: "2"

services:

  db:
    build: db
    restart: unless-stopped
    volumes:
      - ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - POSTGRES_USER=mmuser
      - POSTGRES_PASSWORD= mmuser_password
      - POSTGRES_DB=mattermost
    # uncomment the following to enable backup
    # - AWS_ACCESS_KEY_ID=XXXX
    # - AWS_SECRET_ACCESS_KEY=XXXX
    # - WALE_S3_PREFIX=s3://BUCKET_NAME/PATH
    # - AWS_REGION=us-east-1

  app:
    build:
      context: app
      # comment out for team edition
      # dockerfile: Dockerfile-enterprise
    restart: unless-stopped
    volumes:
      - ./volumes/app/mattermost/config:/mattermost/config:rw
      - ./volumes/app/mattermost/data:/mattermost/data:rw
      - ./volumes/app/mattermost/logs:/mattermost/logs:rw
      - /etc/localtime:/etc/localtime:ro
    environment:
      # set same as db credentials and dbname
      - MM_USERNAME=mmuser
      - MM_PASSWORD= mmuser_password
      - MM_DBNAME=mattermost
      - VIRTUAL_HOST=mymattermost.tld
      - LETSENCRYPT_HOST=mymattermost.tld
      - LETSENCRYPT_EMAIL=me@mymattermost.tld
    expose:
      - "80"
      - "443"
    links:
      - db:db

```

---

<div class="post-metadata">

**Author:** ![JesseChang](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@JesseChang](https://forum.mattermost.com/u/JesseChang)\
**Post date:** [June 25, 2019, 9:31am UTC](https://forum.mattermost.com/t/use-nginx-proxy-and-v3-7-1-docker/3062/5 "2019-06-25T09:31:39Z")

</div>

for anyone follow to this post, if you’re using team edition, you have to expose ‘8000’ in app block.
