Install Mattermost on QNAP NAS with Container Station

Installing Mattermost on a QNAP server is achievable using Container Station. Mattermost provides a Docker container that makes this installation a pretty straightforward process with the correct configuration. Mattermost does require a Postgres database to store the data in, which is not built into the Mattermost Docker container or the QNAP platform. For that reason a second container with Postgres is required as well.

This tutorial walks through the steps to get Mattermost installed on a QNAP server. Setting the configuration of the networking of the Mattermost container correctly is critical to getting this talking to the Postgres container. With that set, a Mattermost chat server will be up and running before you know it!

While Mattermost provides deployment guides, they don’t seem to be sufficient enough on how to deploy Mattermost to a Qnap server. That’s where this how to guide fills in the missing pieces with steps on how to install Mattermost on a Qnap server with success.

How to install Mattermostt on QNAP with Container Station

Why Use Mattermost

Mattermost is a pretty amazing opensource option for an enterprise grade chat / instant messaging platform. Mattermost is a solid alternative to Rocket Chat and Slack in so many ways, but yet so much more! Mattermost provides Boards for project management that replaces the need for Trello in a management suite. In addition Mattermost has built in Playbooks as a cool tool for ensuring repeatable processes are executed with precision over and over!

While Mattermost offers a free version, there is a paid tier that adds additional features and unlocks some premium features. More information can be can be found on the Mattermost pricing page.

What is Needed to Run Mattermost on a QNAP NAS?

The Wrong Way to Install Mattermost on QNAP

In the QNAP App Center there is an app for Mattermost. Installing through the App Center will quickly get Mattermost up and running. However, it is highly outdated (version 5.5, current version at the time of writing is 7.9) to the point that the mobile and desktop applications no longer work with this version. It can be accessed through a web browser. The app in App Center is NOT provided by QNAP and thus they will not maintain this app with updated versions. The maintainer of this app obviously has chosen to not update it. There are others out there publishing more up to date apps that can be manually installed, however in my experience those were not stable/reliable options.

The RIGHT Way to Install Mattermost on QNAP

Thankfully QNAP provides Container Station and Mattermost is available as a Docker container. Thus, a simple path to a successful installation is available. There is one (solvable) caveat here – Mattermost requires Postgres as the database to store the chat data in. And thankfully, there’s a container for that!

All that said, the solution to run Mattermost on a QNAP NAS is:

  • Install and run Postgres in Container Station
  • Install and run Mattermost in Container Station
    • The Mattermost container will connect to the Postgres container

Install Postgres via Container Station

Postgres is a database using SQL (standard query language). This is where all the data for Mattermost will be stored – the conversations, users, boards, etc.

These instructions will install Postgres with Container Station 2 in Container Station. Additionally this will install phppgadmin as well – a web interface that can be used to access and manage the Postgres database.

  1. Open Container Station
  2. Click the Create menu option in the left hand menu
  3. Click the + Create Application button in the top right
    • Create application in Container Station
  4. In the bottom left corner of the new screen, select PostgreSQL from the Sample dropdown
    • Select the Postgres sample template
  5. Optional Configuration:
    • Username and Password:
      • The default username and password are defined by the POSTGRES_USER and POSTGRES_PASSWORD variables in the postgres environment section. The default for both are qnap_postgres
      • The username and password can be changed at this time if desired.
    • Data Storage Location:
      • The default location that the data will be stored is: /share/Container/postgresdb:/var/lib/postgresql/data
      • This location can be changed in the poastgres volumes section of the YAML configuration here.
    • phppgadmin:
      • If phppgadmin isn’t desired, remove that section of configuration from the YAML file here before proceeding. This is not recommended…
  6. Click Create
  7. Wait until this is done

Postgres is now installed and running. Clicking on the Container left hand menu option in Container Station should show Memory and CPU usage for this container to confirm it’s online.

Create a Database for Mattermost in Postgres

A database needs to be created in Postgres for the Mattermost application. This should be done before setting up the Mattermost container.

  1. Open Container Station
  2. Click the Container menu option in the left hand menu
  3. Click the triangle icon on the left hand side of the Postgres application to expand it
  4. Click the link icon for the phppgadmin container to open the phppgadmin web application.
    • It may take a few seconds for this icon to show.
    • Open phppgadmin from the Container Station application
  5. In the phppgadmin web interface, click on the PostgreSQL text link in the top left and login with the username and password from creating the container.
  6. Click the Create Database text link.
    • Click the Create Database link in phppgadmin
  7. Enter a name in the Name field
  8. Click the Create button

Now that a database has been setup all the pre-requisites are complete. The next step is to install Mattermost.

Install Mattermost via Container Station

Mattermost is the actual chat software that needs to be installed. It’ll utilize the Postges database that was created above to store the data.

There are two ways to install Mattermost in Container Station. It is strongly suggested that you utilize an Application within Container Station (Option 1) using Mattermost yml configuration as it provides a bit more flexibility in the setup that results in controlling where the data for the container is stored. This is important for when the version is updated [tutorial] that it always references the same volume. If not, images, log data, etc. will not be connected and will result in an issue. The alternative method is to install a Container using the Container Station GUI (Option 2). This method doesn’t provide the necessary ability to set the Linux user and container directories correctly.

Despite the strong recommendation to install Mattermost via an Application (Option 1), both options are provided here as a reference.

Option 1: Create an Application in Container Station (preferred method)

When creating the application, a location to store images and files will be defined. This can be reused when installing future updated versions of the Mattermost docker image. This makes for easy upgrades in the future with no degradation to the user experience as the locations referenced in the database will always point to the location specified in the yml configuration.

If you’re not familiar with yml (or yaml) configuration, don’t worry. The supplied sample below is complete and provides what is needed to get up and running. YAML (which stands for yet another markup language) is a clean simple way to define configuration that Docker (the technology that is really running behind Container Station) uses to setup your system.

Since Mattermost will be writing data (images, files, logs, etc.) to the filesystem a Linux/QNAP username and group need to be specified in the yaml configuration. Technically speaking the admin:administrators user and group pair could be used (0:0). This is bad practice however as that user has the highest level of access to the system. If you don’t know much about cyber-security consider this your first lesson: don’t give software any more access/privileges than it needs. Software can’t be malicious if it doesn’t have access to things it shouldn’t. (case and point: lastpass hacked through a developers installation of Plex on their device)

After that is done, we get the Docker image and use it in an Application and Mattermost will be up and running!

Create a Directory to Store Mattermost Content

A directory needs to be made to store the Mattermost content (images, log data, etc.) in the filesystem.

  1. Login to the QNAP web admin
  2. From the main menu, choose File Station
  3. Select the Container directory in the root level of the file structure in the left hand menu
  4. Click the + folder icon and choose Folder to create a new folder
  5. Enter the name mattermost and click Ok.

Create a QNAP User and Group

  1. Login to the QNAP web admin
  2. From the main menu choose Users
  3. Select the User Groups tab
  4. Click the Create button
    • Enter Integrations into the User group name: field
    • Click the Create button
  5. Select the Users tab
  6. Click the Create button and choose Create a User
    • Enter Mattermost in the Username field
    • Enter a password in the Password and Verify Password fields
    • Click the Edit button in the User Group section and check the Integrations group
    • Click the Edit button in the Shared Folder Permissions
    • Check the RW (read and write) box for the Container directory and Deny for all of the other directories.
    • Click the Edit button for the Edit Application Privilege section.
    • Uncheck all of the Application options.
    • Click the Create button
Create a user in QNAP for Container Station access

Get the New User and Group IDs

Users and groups in a Linux operating system (Linux is the kernel that QNAP runs on) are assigned a numeric ID. These will be needed to configure the Mattermost Application yaml. Sadly QNAP doesn’t expose these IDs in the web admin, so SSH access will be needed to find these IDs. If you don’t have SSH access setup to the server yet, follow the QNAP SSH tutorial to get that access setup.

Linux stores the user and group information in files /etc/passwd and /etc/groups respectively. A command line based program called grep can search a file and return the lines that match. Another program awk can be used to parse the line returned to get just specific data that is desired. These values will be needed in the step below for the Mattermost yaml code.

Get User ID (UID) via Command Line for Specific User Name
Get Group ID (GID) via Command Line for Specific Group Name

Get the Mattermost Image from Docker Hub

Mattermost publishes an image of their software on Docker Hub that will be used by the Container Station application in QNAP to run Mattermost. That image needs to be fetched from Docker Hub to the QNAP server.

  1. Login to the QNAP web admin
  2. From the main menu choose Container Station
  3. From the left hand menu select Images
  4. Click the Pull button
    • Registry: Docker Hub
    • Image Name: mattermost/mattermost-enterprise-edition
    • Image Version: latest
    • Click the Pull button

It’ll take a little while for the image to pull down. A progress bar is shown in the top right corner of the Container Station window in the Background Tasks dropdown menu.

Create the Mattermost Application in Container Station

All the steps above finally lead to the point we’ve really wanted to get to – being able to actually install Mattermost! This step is where the Mattermost software will be installed onto the QNAP server.

  1. Login to the QNAP web admin
  2. From the main menu choose Container Station
  3. Click on Create in the left hand menu
  4. Click the + Create Application button
  5. Enter a recognizable name in the Application Name field like mattermostenterprise77 (alphanumeric only allowed)
  6. Copy and paste the below yaml into the YAML text box (replacing anything else in the box). Replace values in the sample code below like <sample> with your specific values.
  1. Click the Validate YAML button. If you get a green checkmark you’re clear to proceed. If not, something in the yaml configuration needs to be adjusted and re-validated.
  2. Click the Create button
  3. It’ll take a minute or two for the application to be created and start running.
    • The Container Station background tasks icon (top right) will show this process.
    • Even after that is done it’ll take a few minutes for the container to fully load.
      • Click on Container in the left hand menu
      • Click the triangle icon on the left hand side of the Mattermost application
      • Click on the blue text link of the Docker container in the application. In the black portion of the screen is a log of what the container is doing and should indicate when the system is up and running.

Option 2: Install a Container in Container Station (non-preferred method)

This method utilizes the pre-built container configuration provided by the Mattermost docker container. The container is created using the Container Station graphical interface. This will result in a system-defined location of the volume that will not persist when the container is updated [tutorial] in Container Station to a newer version of Mattermost, thus breaking all of the images and files shared in Mattermost. This is a very fast and easy method to setup, though the speed gain is negligible over Option 1.

  1. Open Container Station
  2. Click the Create menu option in the left hand menu
  3. Search for mattermost in the search box
  4. Select the Docker Hub tab
  5. Click the Install button for the mattermost/mattermost-enterprise-edition option.
    • The mattermost/mattermost-team-edition is a usable option as well however not recommended. The enterprise option is the full suite which includes the team version in it. If a paid plan will be used, enterprise is the required option here. The Mattermost explanation of the difference of these options can be found here: Mattermost Editions Explained
    • Install the Mattermost  Enterprise container from Docker Hub
  6. Select latest from the dropdown
    • If a specific version is desired, this is where that would be selected
  7. The default settings for the container are sufficient for most of the configuration. But a few custom settings need to be set.
    • On the Create Container page:
      • Set the CPU Limit to 75%
      • Set the Memory Limit to around 75%
    • Click on Advanced Settings >>
    • On the Environment tab:
      • Click the Add button and add the following settings:
        • MM_FEATUREFLAGS_BoardsProduct = true
        • MM_NO_DOCKER = true
        • MM_SERVICESETTINGS_SITEURL = http://<ip-address-of-the-qnap-server>:8065
        • MM_SQLSETTINGS_DATASOURCE = postgres://<postres-username-from-postres-app-setup>:<postres-password-from-postres-app-setup>@127.0.0.1:5432/mattermost?sslmode=disable&connect_timeout=10
    • On the Network tab:
      • Set the Network Mode to Host
  8. Click the Create button

Accessing Mattermost

Regardless if Option 1 or Option 2 were used, once those steps are complete Mattermost can be accessed and used!

Open Mattermost via a web browser at http://<ip-address-of-the-qnap-server>:8065.

Alternatively Mattermost provides desktop and mobile applications. Those applications will ask for the same address as the web browser uses to connect to the Mattermost server.

Image Storage

Mattermost stores images in two ways. In the Postgres database table fileinfo is where this information is stored.

  1. An extremely low resolution base64 encoded representation of the image is stored in field minipreview in table fileinfo.
  2. Various sizes of the image are stored in the filesystem in the data directory and the filename/path is specified in table fileinfo.

Images are stored in dated directories.

If Option 1 was used to install Mattermost, the location on the filesystem of the data directory for the full-sized images was specified. This makes it easy if the server ever needs to be migrated, data recovery is needed, etc. Additionally, if the docker container is ever updated to a newer version for security or feature reasons, the directory of the images is known and thus not an issue to ensure the updated version is connected to.

However if Option 2 was used a random hashname is used for the image directory and is stored in a location like this: /share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/982c23e022dfc41037219e71763b87b699dc1bf04724c256f7213f9e40a38064/_data. Then when the container is updated some day in the future a new random hash will be used, thus losing the connection to the older images. Copying/moving the images from the old directory should reconnect them to Mattermost as the directory name is not stored in the database, however in my experience I struggled to reconnect all images in a move. Thus why I recommend the slight extra effort of Option 1.

QNAP Specifications

Any QNAP server should work, but for reference this is the configuration this tutorial was based on.

  • QNAP TS-251 (buy on Amazon)
    • 4GB RAM
  • QTS 5.0.1.2277
  • Container Station 2
  • Mattermost Enterprise 7.7
This post may contain affiliate links, which means I'll receive a commission if you purchase through my links, at no extra cost to you. Please read full disclosure for more information.