# How to secure Mattermost on docker and a few more questions

**URL:** <https://forum.mattermost.com/t/how-to-secure-mattermost-on-docker-and-a-few-more-questions/19233>\
**Category:** Troubleshooting\
**Created:** [August 8, 2024, 4:54am UTC](https://forum.mattermost.com/t/how-to-secure-mattermost-on-docker-and-a-few-more-questions/19233 "2024-08-08T04:54:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve80](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Steve80](https://forum.mattermost.com/u/Steve80)\
**Post date:** [August 8, 2024, 4:54am UTC](https://forum.mattermost.com/t/how-to-secure-mattermost-on-docker-and-a-few-more-questions/19233/1 "2024-08-08T04:54:15Z")

</div>

**Summary**  
I have installed Mattermost on Ubuntu server and planing to run it in production with a small team. I have followed the official guide and use Nginx as reverse proxy. I am getting stuck in chaging the postgresql password in the env file. Whenever I do it, nginx stops working with an error (502). Hoq should I do that? Is there anything else from a security perspective I should consider?

Also, how would I simply update Mattermost to a new version with this setup now?

Thank you a lot  
Stefano

---

<div class="post-metadata">

**Author:** ![john.combs](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/john.combs/32/7118_2.png) [@john.combs](https://forum.mattermost.com/u/john.combs)\
**Post date:** [August 10, 2024, 12:40am UTC](https://forum.mattermost.com/t/how-to-secure-mattermost-on-docker-and-a-few-more-questions/19233/2 "2024-08-10T00:40:37Z")

</div>

Hi Stefano! It’s great to hear that you’re setting up Mattermost for your team!

To change the PostgreSQL password in the `.env` file without disrupting Nginx, make sure to update the corresponding database credentials in your Mattermost configuration file as well.

You can refer to the [Mattermost documentation on database setup](https://docs.mattermost.com/install/prepare-mattermost-database.html) for more details. For updating Mattermost, here’s a guide on [deploying to Docker](https://docs.mattermost.com/install/install-docker.html).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Steve80](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Steve80](https://forum.mattermost.com/u/Steve80)\
**Post date:** [August 10, 2024, 3:34am UTC](https://forum.mattermost.com/t/how-to-secure-mattermost-on-docker-and-a-few-more-questions/19233/3 "2024-08-10T03:34:20Z")

</div>

thank you John for the reply! So to clarify should I change also the password in the service or just the env and update the compose file? or do you mean the config file of Postgres?

I was thinking of changing the password in the env file and then use the postgres command inside the container to update it but I am not sure that’s enough and it’s not 100% clear from the documentation.

I followed the official doc to install it with docker so I have nginx as well as a container

thanks again

---

<div class="post-metadata">

**Author:** ![john.combs](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/john.combs/32/7118_2.png) [@john.combs](https://forum.mattermost.com/u/john.combs)\
**Post date:** [August 13, 2024, 6:46pm UTC](https://forum.mattermost.com/t/how-to-secure-mattermost-on-docker-and-a-few-more-questions/19233/4 "2024-08-13T18:46:07Z")

</div>

Hi Stefano, you’re on the right track! After updating the password in the `.env` file, you’ll also need to change the PostgreSQL password inside the container to ensure everything aligns. You can use the PostgreSQL command within the container to update it, but make sure to also update the Mattermost configuration file (`config.json`) to match the new credentials.

---

<div class="post-metadata">

**Author:** ![Steve80](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Steve80](https://forum.mattermost.com/u/Steve80)\
**Post date:** [August 14, 2024, 9:15am UTC](https://forum.mattermost.com/t/how-to-secure-mattermost-on-docker-and-a-few-more-questions/19233/5 "2024-08-14T09:15:17Z")

</div>

Thank you John, I tried changing it on the postgres command line and on the env file (docker compose file uses the env variables). Still not working because what I see in the config.json is the following:

**CONFIG JSON:**

“SqlSettings”: {  
“DriverName”: “postgres”,  
“DataSource”: “postgres://mmuser:mostest@localhost/mattermost\_test?sslmode=disable\u0026connect\_timeout=10\u0026binary\_parameters=yes”,  
“DataSourceReplicas”: ,  
“DataSourceSearchReplicas”: ,  
“MaxIdleConns”: 20,  
“ConnMaxLifetimeMilliseconds”: 3600000,  
“ConnMaxIdleTimeMilliseconds”: 300000,  
“MaxOpenConns”: 300,  
“Trace”: false,  
“AtRestEncryptKey”: “ruskdddxc4yao8osghji9e1yfng4facs”,  
“QueryTimeout”: 30,  
“DisableDatabaseSearch”: false,  
“MigrationsStatementTimeoutSeconds”: 100000,  
“ReplicaLagSettings”: ,  
“ReplicaMonitorIntervalSeconds”: 5  
},

ENV FILE:  
POSTGRES\_IMAGE\_TAG=13-alpine

POSTGRES\_DATA\_PATH=./volumes/db/var/lib/postgresql/data

POSTGRES\_USER=mmuser

POSTGRES\_PASSWORD=mmuser\_password

POSTGRES\_DB=mattermost

while on the env file I have different username and database. Where is the mistake? Which database am I really using?

---

<div class="post-metadata">

**Author:** ![Steve80](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Steve80](https://forum.mattermost.com/u/Steve80)\
**Post date:** [August 14, 2024, 9:35am UTC](https://forum.mattermost.com/t/how-to-secure-mattermost-on-docker-and-a-few-more-questions/19233/6 "2024-08-14T09:35:35Z")

</div>

UPDATE: I checked the data and the database I am really using is the one inside the ENV file. But if I change the password to it I still get a 502 bad gateway, so it means that the config file is really not a reference. What should I do?

this is the command I am using for starting and stopping everything:

sudo docker compose -f docker-compose.yml -f docker-compose.nginx.yml up -d  
sudo docker compose -f docker-compose.yml -f docker-compose.without-nginx.yml down
