# Docker

## Running from DockerHub

We provide prebuilt MongoosePush images. Configuration requires either an FCM token, APNS certificates or an APNS token. Depending on your usecase, you can have some or all of them in a standalone MongoosePush instance or using a docker container.
For the full configuration you need to set up the following directory structure:
* priv/
    * ssl/
      * rest_cert.pem - The HTTP endpoint certificate
      * rest_key.pem - private key for the HTTP endpoint certificate (has to be unencrypted)
    * apns/
      * prod_cert.pem - Production APNS app certificate
      * prod_key.pem - Production APNS app certificate's private key (has to be unencrypted)
      * dev_cert.pem - Development APNS app certificate
      * dev_key.pem - Development APNS app certificate's private key (has to be unencrypted)
      * token.p8 - `APNS` authentication token
    * fcm/
      * token.json - `FCM` service account JSON file
* var/
    * config.toml - TOML configuration file (optional)

If you want to use the `APNS` token authentication you need to provide the token and set both `key_id` and `team_id` environment variables. To see how to obtain the token and `key_id` read [this](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token_based_connection_to_apns).
To see how to obtain `team_id` read [this](https://www.mobiloud.com/help/knowledge-base/ios-app-transfer/).

`FCM` JSON file can be generated by the Firebase console (https://console.firebase.google.com). Go to your project -> `Project Settings` -> `Service accounts` -> `Generate new private key`.

TOML config file is optional. It allows to fully configure the service but basic configuration can be achieved via environmental variables only.

Assuming that you have the `priv` directory with all certificates and fcm token in current directory and `var` directory with a config file, then you may start MongoosePush with the following command:

```bash
docker run -v `pwd`/priv:/opt/app/priv \
  -v `pwd`/var:/opt/app/var \
  -e PUSH_HTTPS_CERTFILE="/opt/app/priv/ssl/rest_cert.pem" \
  -e PUSH_HTTPS_KEYFILE="/opt/app/priv/ssl/rest_key.pem" \
  -it --rm erlangsolutions/mongoose-push:latest
```


## Building

Building a docker image is really easy, just type:

```bash
docker build . -t mpush:latest
```

As a result of this command you get access to the `mpush:latest` docker image. You may run it by typing:

```bash
docker run -it --rm mpush:latest foreground
```

The docker image that you have just built, exposes the port `8443` for the HTTP API of MongoosePush.
It contains a `VOLUME` for path */opt/app/priv* - it is handy for injecting `APNS` and `HTTP API` certificates since by default the docker image comes with test, self-signed certificates.

## Configuration (basic)

The docker image of MongoosePush contains common, basic configuration that is generated from `config/prod.exs`. All useful options may be overridden via [environment variables](configuration.md#environment-variables). You can use TOML config for more control. However, if this is not enough, then you need to prepare your own `config/prod.exs` before image build.
