This repository has been archived on 2021-08-31. You can view files and clone it, but cannot push or open issues or pull requests.
mattermost/README.md

218 lines
8.9 KiB
Markdown
Raw Normal View History

# Production Docker deployment for Mattermost
2015-11-30 07:09:07 +01:00
This project enables deployment of a Mattermost server in a multi-node production configuration using Docker.
2016-04-12 07:09:03 +02:00
2016-04-24 17:44:04 +02:00
[![Build Status](https://travis-ci.org/mattermost/mattermost-docker.svg?branch=master)](https://travis-ci.org/mattermost/mattermost-docker)
Notes:
2017-07-16 12:33:41 +02:00
- The default Mattermost edition for this repo has changed from Team Edition to Enterprise Edition. Please see [Choose Edition](#choose-edition-to-install) section.
- To install this Docker project on AWS Elastic Beanstalk please see [AWS Elastic Beanstalk Guide](contrib/aws/README.md).
2017-06-02 23:56:51 +02:00
- To run Mattermost on Kubernetes you can start with the [manifest examples in the kubernetes folder](contrib/kubernetes/README.md)
- To install Mattermost without Docker directly onto a Linux-based operating systems, please see [Admin Guide](https://docs.mattermost.com/guides/administrator.html#installing-mattermost).
2015-11-30 07:09:07 +01:00
## Installation using Docker Compose
The following instructions deploy Mattermost in a production configuration using multi-node Docker Compose set up.
2015-11-30 07:09:07 +01:00
### Requirements
2015-11-30 07:09:07 +01:00
2018-04-15 19:33:49 +02:00
* [docker] (version `1.12+`)
2018-08-24 14:35:01 +02:00
* [docker-compose] (version `1.10.0+` to support Compose file version `3.0`)
2017-01-31 01:51:36 +01:00
### Choose Edition to Install
2017-07-16 12:33:41 +02:00
If you want to install Enterprise Edition, you can skip this section.
To install the team edition, comment out the two following lines in docker-compose.yaml file:
```yaml
args:
- edition=team
2017-06-02 23:56:51 +02:00
```
The `app` Dockerfile will read the `edition` build argument to install Team (`edition = 'team'`) or Entreprise (`edition != team`) edition.
2017-07-16 12:33:41 +02:00
### Database container
This repository offer a Docker image for the Mattermost database. It is a customized PostgreSQL image that you should configure with following environment variables :
* `POSTGRES_USER`: database username
* `POSTGRES_PASSWORD`: database password
* `POSTGRES_DB`: database name
2017-09-25 18:57:52 +02:00
It is possible to use your own PostgreSQL database, or even use MySQL. But you will need to ensure that Application container can connect to the database (see [Application container](#application-container))
2017-07-16 12:33:41 +02:00
#### AWS
If deploying to AWS, you could also set following variables to enable [Wal-E](https://github.com/wal-e/wal-e) backup to S3 :
* `AWS_ACCESS_KEY_ID`: AWS access key
* `AWS_SECRET_ACCESS_KEY`: AWS secret
* `WALE_S3_PREFIX`: AWS s3 bucket name
* `AWS_REGION`: AWS region
2017-07-16 12:33:41 +02:00
All four environment variables are required. It will enable completed WAL segments sent to archive storage (S3). The base backup and clean up can be done through the following command:
```bash
# Base backup
docker exec mattermost-db su - postgres sh -c "/usr/bin/envdir /etc/wal-e.d/env /usr/local/bin/wal-e backup-push /var/lib/postgresql/data"
# Keep the most recent 7 base backups and remove the old ones
docker exec mattermost-db su - postgres sh -c "/usr/bin/envdir /etc/wal-e.d/env /usr/local/bin/wal-e delete --confirm retain 7"
```
Those tasks can be executed through a cron job or systemd timer.
2015-11-30 07:09:07 +01:00
2017-07-16 12:33:41 +02:00
### Application container
Application container run the Mattermost application. You should configure it with following environment variables :
* `MM_USERNAME`: database username
* `MM_PASSWORD`: database password
* `MM_DBNAME`: database name
2015-11-30 07:09:07 +01:00
2017-07-16 12:33:41 +02:00
If your database use some custom host and port, it is also possible to configure them :
* `DB_HOST`: database host address
* `DB_PORT_NUMBER`: database port
2017-07-16 12:33:41 +02:00
If you use a Mattermost configuration file on a different location than the default one (`/mattermost/config/config.json`) :
* `MM_CONFIG`: configuration file location inside the container.
2017-09-25 18:57:52 +02:00
If you choose to use MySQL instead of PostgreSQL, you should set a different datasource and SQL driver :
* `DB_PORT_NUMBER` : `3306`
* `MM_SQLSETTINGS_DRIVERNAME` : `mysql`
* `MM_SQLSETTINGS_DATASOURCE` : `MM_USERNAME:MM_PASSWORD@tcp(DB_HOST:DB_PORT_NUMBER)/MM_DBNAME?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s`
2017-09-25 18:57:52 +02:00
Don't forget to replace all entries (beginning by `MM_` and `DB_`) in `MM_SQLSETTINGS_DATASOURCE` with the real variables values.
If you want to push Mattermost application to **Cloud Foundry**, use a `manifest.yml` like this one (with external PostgreSQL service):
```
---
applications:
- name: mattermost
docker:
image: mattermost/mattermost-prod-app
instances: 1
memory: 1G
disk_quota: 256M
2018-08-24 14:35:01 +02:00
env:
DB_HOST: database host address
DB_PORT_NUMBER: database port
MM_DBNAME: database name
MM_USERNAME: database username
MM_PASSWORD: database password
2018-08-24 14:35:01 +02:00
```
2017-07-16 12:33:41 +02:00
### Web server container
This image is optional, you should **not** use it when you have your own reverse-proxy. It is a simple front Web server for the Mattermost app container. If you use the provided `docker-compose.yml` file, you don't have to configure anything. But if your application container is reachable on custom host and/or port (eg. if you use a container provider), you should add those two environment variables :
* `APP_HOST`: application host address
* `APP_PORT_NUMBER`: application HTTP port
2017-07-16 12:33:41 +02:00
#### Install with SSL certificate
Put your SSL certificate as `./volumes/web/cert/cert.pem` and the private key that has
no password as `./volumes/web/cert/key-no-password.pem`. If you don't have
them you may generate a self-signed SSL certificate.
### Starting/Stopping Docker
#### Start
2018-04-15 19:33:49 +02:00
If you are running docker with non root user, make sure the UID and GID in app/Dockerfile are the same as your current UID/GID
2017-06-02 23:56:51 +02:00
```
2018-08-22 14:47:58 +02:00
mkdir -p ./volumes/app/mattermost/{data,logs,config,plugins}
2018-04-15 19:33:49 +02:00
chown -R 2000:2000 ./volumes/app/mattermost/
2017-06-02 23:56:51 +02:00
docker-compose start
```
2015-11-30 07:09:07 +01:00
#### Stop
2017-06-02 23:56:51 +02:00
```
docker-compose stop
```
### Removing Docker
2017-03-03 17:16:47 +01:00
#### Remove the containers
2017-06-02 23:56:51 +02:00
```
docker-compose stop && docker-compose rm
2017-06-02 23:56:51 +02:00
```
2017-03-03 17:16:47 +01:00
#### Remove the data and settings of your Mattermost instance
```
sudo rm -rf volumes
```
## Update Mattermost to latest version
First, shutdown your containers to back up your data.
2015-11-30 07:09:07 +01:00
2017-06-02 23:56:51 +02:00
```
docker-compose down
2017-06-02 23:56:51 +02:00
```
2015-11-30 07:09:07 +01:00
Back up your mounted volumes to save your data. If you use the default `docker-compose.yml` file proposed on this repository, your data is on `./volumes/` folder.
Then run the following commands.
2017-06-02 23:56:51 +02:00
```
git pull
docker-compose build
docker-compose up -d
2017-06-02 23:56:51 +02:00
```
Your Docker image should now be on the latest Mattermost version.
2018-04-18 21:40:46 +02:00
## Upgrading Mattermost to 4.9+
Docker images for `4.9.0` release introduce some important changes from [PR #241](https://github.com/mattermost/mattermost-docker/pull/241) to improve production use of Mattermost with Docker.
2018-08-24 14:35:01 +02:00
**There are 2 important changes for existing installations**
2018-04-18 21:40:46 +02:00
One important change is that we don't use `root` user by default to run the Mattermost application. So, as explained on [the README](https://github.com/mattermost/mattermost-docker#start), if you use host mounted volume you have to be sure that files on your host server have the correct UID/GID (by default those values are `2000`). In practice, you should just run following commands :
```
2018-08-22 14:47:58 +02:00
mkdir -p ./volumes/app/mattermost/{data,logs,config,plugins}
2018-04-18 21:40:46 +02:00
chown -R 2000:2000 ./volumes/app/mattermost/
```
2018-08-24 14:35:01 +02:00
The second important change is the port used by Mattermost application container. The default port is now `8000`, and existing installations that use port `80` will not work without a little configuration change. You have to open your Mattermost configuration file (`./volumes/app/mattermost/config/config.json` by default) and change the key `ServiceSettings.ListenAddress` to `:8000`.
2018-04-18 21:40:46 +02:00
Also if you use your own web-server/reverse-proxy you need to change its configuration to reach port `8000` of the Mattermost container.
## Upgrading to Team Edition 3.0.x from 2.x
2017-07-16 12:33:41 +02:00
You need to migrate your database before upgrading Mattermost to `3.0.x` from
`2.x`. Run these commands in the latest `mattermost-docker` directory.
2017-06-02 23:56:51 +02:00
```
docker-compose rm -f app
docker-compose build app
docker-compose run app -upgrade_db_30
docker-compose up -d
```
See the [offical Upgrade Guide](http://docs.mattermost.com/administration/upgrade.html) for more details.
## Installation using Docker Swarm Mode
The following instructions deploy Mattermost in a production configuration using docker swarm mode on one node.
Running containerized applications on multi-node swarms involves specific data portability and replication handling that are not covered here.
### Requirements
* [docker] (1.12.0+)
### Swarm Mode Installation
First, create mattermost directory structure on the docker hosts:
```
2018-08-22 14:47:58 +02:00
mkdir -p /var/lib/mattermost/{cert,config,data,logs,plugins}
```
Then, fire up the stack in your swarm:
```
docker stack deploy -c contrib/swarm/docker-stack.yml mattermost
```
2015-12-03 16:40:11 +01:00
## Known Issues
* Do not modify the Listen Address in Service Settings.
2017-07-16 12:33:41 +02:00
* Rarely `app` container fails to start because of "connection refused" to
database. Workaround: Restart the container.
2015-12-03 16:40:11 +01:00
## More information
2015-11-30 07:09:07 +01:00
If you want to know how to use docker-compose, see [the overview
page](https://docs.docker.com/compose).
2017-07-16 12:33:41 +02:00
For the server configurations, see [prod-ubuntu.rst] of Mattermost.
2015-11-30 07:09:07 +01:00
[docker]: http://docs.docker.com/engine/installation/
[docker-compose]: https://docs.docker.com/compose/install/
2018-02-11 12:28:25 +01:00
[prod-ubuntu.rst]: https://docs.mattermost.com/install/install-ubuntu-1604.html