Log inSign up

Mattermost: your own team chat server

Clone the official mattermost/docker repository, copy env.example to .env, set DOMAIN, prepare the volume folders owned by UID 2000, and start it with the docker-compose.without-nginx.yml overlay. Your own Nginx then terminates HTTPS and forwards WebSockets to port 8065.

Topic: Self-hosted apps · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

How big should a Mattermost server be?

Mattermost with PostgreSQL on the same machine needs at least 2 GB of memory for a small team; 4 GB keeps search, file previews and plugins responsive for a few dozen active users. Message history is compact, but uploaded files grow steadily, so leave disk headroom.

You need Ubuntu 24.04, Ubuntu 22.04, Debian 12 or Debian 13 with Docker Engine and the Compose plugin (install it first), plus a DNS name such as chat.example.net. Mattermost also offers an apt repository for Ubuntu; the Docker route below works the same on all four systems.

How do you prepare the deployment folder?

cd /opt
sudo git clone https://github.com/mattermost/docker mattermost
sudo chown -R deploy:deploy /opt/mattermost
cd /opt/mattermost
cp env.example .env
nano .env

In .env, change these lines and leave the rest at their defaults for now:

DOMAIN=chat.example.net
TZ=UTC
POSTGRES_PASSWORD=a-long-random-db-pass
MATTERMOST_IMAGE_TAG=pick-a-current-release

Use a current release number from the Mattermost changelog for the image tag; extended support releases (ESR) are the calmer choice for production. Then create the data folders and hand them to the user ID the container runs as:

mkdir -p ./volumes/app/mattermost/{config,data,logs,plugins,client/plugins,bleve-indexes}
sudo chown -R 2000:2000 ./volumes/app/mattermost

How do you keep the app port private and start it?

The without-nginx overlay publishes port 8065 for your own proxy, plus port 8443 for Calls. Edit docker-compose.without-nginx.yml so the web port listens only on loopback:

    ports:
      - "127.0.0.1:${APP_PORT}:8065"
      - "${CALLS_PORT}:${CALLS_PORT}/udp"
      - "${CALLS_PORT}:${CALLS_PORT}/tcp"

Then bring the stack up:

docker compose -f docker-compose.yml -f docker-compose.without-nginx.yml up -d
docker compose -f docker-compose.yml -f docker-compose.without-nginx.yml ps
curl -s http://127.0.0.1:8065/api/v4/system/ping

A JSON reply containing "status":"OK" confirms the server and database are talking. The running version shows in the System Console under About.

How do you configure Nginx with WebSockets?

Mattermost pushes messages over a WebSocket, so the proxy must pass the upgrade and allow long idle connections.

upstream mattermost_backend {
    server 127.0.0.1:8065;
    keepalive 32;
}
server {
    listen 80;
    listen [::]:80;
    server_name chat.example.net;
    client_max_body_size 100m;

    location ~ /api/v[0-9]+/(users/)?websocket$ {
        proxy_pass http://mattermost_backend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 600s;
    }
    location / {
        proxy_pass http://mattermost_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d chat.example.net

Save the block as /etc/nginx/sites-available/mattermost before the first command. Background reading: Nginx as a reverse proxy.

Which firewall ports does Mattermost need?

Web traffic needs 80 and 443. If you use the built-in Calls plugin for voice and screen sharing, clients also need port 8443 over UDP (with TCP as a fallback).

sudo ufw allow 'Nginx Full'
sudo ufw allow 8443/udp
sudo ufw allow 8443/tcp
sudo ufw status

Docker publishes the Calls port itself, but writing the rules keeps your UFW list an accurate record. In the System Console under Plugins, Calls, confirm the RTC server port matches.

How do you finish setup in the browser?

Open https://chat.example.net, create the first account (it becomes the system admin), and name your first team. Then visit the System Console:

  • Environment, Web Server: check that Site URL reads https://chat.example.net.
  • Authentication, Signup: turn off open account creation, or restrict it to your email domain, and invite people by link instead.
  • Authentication, MFA: enable multi-factor authentication.

Desktop and mobile apps connect with the same address.

How do you enable email notifications?

Mattermost emails people about mentions they missed, invitations and password resets. Configure it in the System Console under Environment, SMTP. Since port 25 may be closed for outgoing mail (a support ticket can confirm before you depend on it), use an authenticated relay as covered in the SMTP relay guide: SMTP server smtp.relay.example.net, port 587, connection security STARTTLS, authentication on with the relay username and password. Press Test Connection, then set the notification sender address under Site Configuration, Notifications.

How do you back up and upgrade Mattermost?

Back up the database and the file store together:

cd /opt/mattermost
docker compose exec -T postgres pg_dump -U mmuser mattermost | gzip > ~/mm-db-$(date +%F).sql.gz
sudo tar czf ~/mm-files-$(date +%F).tar.gz volumes/app/mattermost .env

The database user and name match POSTGRES_USER and POSTGRES_DB in .env. To upgrade, read the important upgrade notes for the target version, raise MATTERMOST_IMAGE_TAG, then:

docker compose -f docker-compose.yml -f docker-compose.without-nginx.yml pull
docker compose -f docker-compose.yml -f docker-compose.without-nginx.yml up -d

Upgrade step by step through ESR versions when you are several releases behind. The daily backup add-on adds a full-disk safety net.

What are typical Mattermost issues?

  • "Cannot connect to the server" banner: WebSocket requests are not reaching port 8065 with the upgrade headers.
  • Container restarts with permission errors: the volume folders are not owned by UID 2000.
  • Calls connect but no audio: UDP 8443 is blocked, or the plugin is announcing the wrong public address; set the ICE host override to 198.51.100.24.
  • Upload rejected: raise client_max_body_size and Maximum File Size in the console.

Other chat and team tools are listed under self-hosting.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A2-4small team chat with file sharing2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months
A4-8larger team with Calls and plugins4 vCPU, 8 GB RAM, 180 GB NVMe$28.80/mo$86.40 for 3 months

Questions about Mattermost team chat

Is Mattermost free to self-host?

Yes. Without a license key the server runs the free feature set; paid licenses unlock enterprise features.

Can Mattermost import from other chat tools?

Yes. It has import tools for several common chat export formats; the import runs through the mmctl command line.

Do I need the Calls port?

Only for voice calls and screen sharing through the Calls plugin. Text chat works over 443 alone.

How many users can a 4 GB server handle?

A few dozen active users with PostgreSQL on the same machine is a reasonable start. Watch memory with usage monitoring and move up a plan when needed.

Can I use the apt package instead of Docker?

Yes. Mattermost publishes an apt repository for supported Ubuntu releases. You then install PostgreSQL separately and manage the service with systemd.