2018-08-04 18:03:50 +02:00
# Install Mailu on a docker swarm
2018-08-04 17:27:27 +02:00
## Prequisites
### Swarm
2018-08-04 18:09:18 +02:00
In order to deploy Mailu on a swarm, you will first need to initialize the swarm:
2018-08-04 17:33:08 +02:00
The main command will be:
```bash
docker swarm init --advertise-addr < IP_ADDR >
```
2018-08-04 17:27:27 +02:00
See https://docs.docker.com/engine/swarm/swarm-tutorial/create-swarm/
2018-08-04 17:38:25 +02:00
2018-08-04 17:33:08 +02:00
If you want to add other managers or workers, please use:
```bash
docker swarm join --token xxxxx
```
2018-08-04 17:27:27 +02:00
See https://docs.docker.com/engine/swarm/join-nodes/
2018-08-04 17:33:08 +02:00
You have now a working swarm, and you can check its status with:
2018-08-04 17:27:27 +02:00
```bash
core@coreos-01 ~/git/Mailu/docs/swarm/1.5 $ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
2018-08-04 17:33:08 +02:00
xhgeekkrlttpmtgmapt5hyxrb black-pearl Ready Active 18.06.0-ce
sczlqjgfhehsfdjhfhhph1nvb * coreos-01 Ready Active Leader 18.03.1-ce
mzrm9nbdggsfz4sgq6dhs5i6n flying-dutchman Ready Active 18.06.0-ce
2018-08-04 17:27:27 +02:00
```
### Volume definition
2018-08-04 18:03:50 +02:00
For data persistance (the Mailu services might be launched/relaunched on any of the swarm nodes), we need to have Mailu data stored in a manner accessible by every manager or worker in the swarm.
2018-08-04 17:38:25 +02:00
Hereafter we will use a NFS share:
2018-08-04 17:27:27 +02:00
```bash
2018-08-04 18:03:50 +02:00
core@coreos-01 ~ $ showmount -e 192.168.0.30
2018-08-04 17:27:27 +02:00
Export list for 192.168.0.30:
/mnt/Pool1/pv 192.168.0.0
```
on the nfs server, I am using the following /etc/exports
```bash
$more /etc/exports
/mnt/Pool1/pv -alldirs -mapall=root -network 192.168.0.0 -mask 255.255.255.0
```
2018-08-04 18:03:50 +02:00
on the nfs server, I created the Mailu directory (in fact I copied a working Mailu set-up)
2018-08-04 17:27:27 +02:00
```bash
$mkdir /mnt/Pool1/pv/mailu
```
On your manager node, mount the nfs share to check that the share is available:
```bash
core@coreos-01 ~ $ sudo mount -t nfs 192.168.0.30:/mnt/Pool1/pv/mailu /mnt/local/
```
If this is ok, you can umount it:
2018-08-04 17:38:25 +02:00
```bash
core@coreos-01 ~ $ sudo umount /mnt/local/
2018-08-04 17:27:27 +02:00
```
### Networking mode
On a swarm, the services are available (default mode) through a routing mesh managed by docker itself. With this mode, each service is given a virtual IP adress and docker manages the routing between this virtual IP and the container(s) provinding this service.
2018-08-04 17:44:43 +02:00
With this default networking mode, I cannot get login working properly... As found in https://github.com/Mailu/Mailu/issues/375 , a workaround is to use the dnsrr networking mode at least for the front services.
2018-08-04 17:47:10 +02:00
The main consequence/limitation will be that the front services will *not* be available on every node, but only on the node where it will be deployed. In my case, I have only one manager and I choose to deploy the front service to the manager node, so I know on wich IP the front service will be available (aka the IP adress of my manager node).
2018-08-04 17:27:27 +02:00
### Variable substitution
The docker stack deploy command doesn't support variable substitution in the .yml file itself (vut we still can use .env file to pass variables to the services). As a consequence we need to adjust the docker-compose file to :
- remove all variables : $VERSION , $BIND_ADDRESS4 , $BIND_ADDRESS6 , $ANTIVIRUS , $WEBMAIL , etc
- change the way we define the volumes (nfs share in our case)
### Docker compose
2018-08-04 18:00:57 +02:00
A working docker-compose-stack.yml file is available here:
2018-08-04 17:27:27 +02:00
2018-08-04 17:38:25 +02:00
```yaml
version: '3.2'
services:
front:
image: mailu/nginx:1.5
env_file: .env
ports:
- target: 80
published: 80
mode: host
- target: 443
published: 443
mode: host
- target: 110
published: 110
mode: host
- target: 143
published: 143
mode: host
- target: 993
published: 993
mode: host
- target: 995
published: 995
mode: host
- target: 25
published: 25
mode: host
- target: 465
published: 465
mode: host
- target: 587
published: 587
mode: host
volumes:
2018-08-04 18:08:07 +02:00
# - "$ROOT/certs:/certs"
2018-08-04 17:38:25 +02:00
- type: volume
source: mailu_certs
target: /certs
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
redis:
image: redis:alpine
restart: always
volumes:
2018-08-04 18:08:07 +02:00
# - "$ROOT/redis:/data"
2018-08-04 17:38:25 +02:00
- type: volume
source: mailu_redis
target: /data
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
imap:
2018-08-04 17:44:43 +02:00
image: mailu/dovecot:1.5
2018-08-04 17:38:25 +02:00
restart: always
env_file: .env
volumes:
# - "$ROOT/data:/data"
- type: volume
source: mailu_data
target: /data
# - "$ROOT/mail:/mail"
- type: volume
source: mailu_mail
target: /mail
# - "$ROOT/overrides:/overrides"
- type: volume
source: mailu_overrides
target: /overrides
depends_on:
- front
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
smtp:
2018-08-04 17:44:43 +02:00
image: mailu/postfix:1.5
2018-08-04 17:38:25 +02:00
restart: always
env_file: .env
volumes:
# - "$ROOT/data:/data"
- type: volume
source: mailu_data
target: /data
# - "$ROOT/overrides:/overrides"
- type: volume
source: mailu_overrides
target: /overrides
depends_on:
- front
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
2018-08-04 17:27:27 +02:00
2018-08-04 17:38:25 +02:00
antispam:
2018-08-04 17:44:43 +02:00
image: mailu/rspamd:1.5
2018-08-04 17:38:25 +02:00
restart: always
env_file: .env
depends_on:
- front
volumes:
# - "$ROOT/filter:/var/lib/rspamd"
- type: volume
source: mailu_filter
target: /var/lib/rspamd
# - "$ROOT/dkim:/dkim"
- type: volume
source: mailu_dkim
target: /dkim
# - "$ROOT/overrides/rspamd:/etc/rspamd/override.d"
- type: volume
source: mailu_overrides_rspamd
target: /etc/rspamd/override.d
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
antivirus:
image: mailu/none:1.5
restart: always
env_file: .env
volumes:
2018-08-04 18:08:07 +02:00
# - "$ROOT/filter:/data"
2018-08-04 17:38:25 +02:00
- type: volume
source: mailu_filter
target: /data
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
webdav:
image: mailu/none:1.5
restart: always
env_file: .env
volumes:
2018-08-04 18:08:07 +02:00
# - "$ROOT/dav:/data"
2018-08-04 17:38:25 +02:00
- type: volume
source: mailu_dav
target: /data
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
admin:
2018-08-04 17:44:43 +02:00
image: mailu/admin:1.5
2018-08-04 17:38:25 +02:00
restart: always
env_file: .env
volumes:
2018-08-04 18:08:07 +02:00
# - "$ROOT/data:/data"
2018-08-04 17:38:25 +02:00
- type: volume
source: mailu_data
target: /data
2018-08-04 18:08:07 +02:00
# - "$ROOT/dkim:/dkim"
2018-08-04 17:38:25 +02:00
- type: volume
source: mailu_dkim
target: /dkim
- /var/run/docker.sock:/var/run/docker.sock:ro
depends_on:
- redis
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
webmail:
image: "mailu/roundcube:1.5"
restart: always
env_file: .env
volumes:
2018-08-04 18:08:07 +02:00
# - "$ROOT/webmail:/data"
2018-08-04 17:38:25 +02:00
- type: volume
source: mailu_data
target: /data
depends_on:
- imap
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
fetchmail:
image: mailu/fetchmail:1.5
restart: always
env_file: .env
volumes:
2018-08-04 18:08:07 +02:00
# - "$ROOT/data:/data"
2018-08-04 17:38:25 +02:00
- type: volume
source: mailu_data
target: /data
logging:
driver: none
deploy:
endpoint_mode: dnsrr
replicas: 1
placement:
constraints: [node.role == manager]
volumes:
mailu_filter:
driver_opts:
type: "nfs"
o: "addr=192.168.0.30,nolock,soft,rw"
device: ":/mnt/Pool1/pv/mailu/filter"
mailu_dkim:
driver_opts:
type: "nfs"
o: "addr=192.168.0.30,nolock,soft,rw"
device: ":/mnt/Pool1/pv/mailu/dkim"
mailu_overrides_rspamd:
driver_opts:
type: "nfs"
o: "addr=192.168.0.30,nolock,soft,rw"
device: ":/mnt/Pool1/pv/mailu/overrides/rspamd"
mailu_data:
driver_opts:
type: "nfs"
o: "addr=192.168.0.30,nolock,soft,rw"
device: ":/mnt/Pool1/pv/mailu/data"
mailu_mail:
driver_opts:
type: "nfs"
o: "addr=192.168.0.30,nolock,soft,rw"
device: ":/mnt/Pool1/pv/mailu/mail"
mailu_overrides:
driver_opts:
type: "nfs"
o: "addr=192.168.0.30,nolock,soft,rw"
device: ":/mnt/Pool1/pv/mailu/overrides"
mailu_dav:
driver_opts:
type: "nfs"
o: "addr=192.168.0.30,nolock,soft,rw"
device: ":/mnt/Pool1/pv/mailu/dav"
mailu_certs:
driver_opts:
type: "nfs"
o: "addr=192.168.0.30,nolock,soft,rw"
device: ":/mnt/Pool1/pv/mailu/certs"
mailu_redis:
driver_opts:
type: "nfs"
o: "addr=192.168.0.30,nolock,soft,rw"
device: ":/mnt/Pool1/pv/mailu/redis"
```
2018-08-04 17:58:53 +02:00
2018-08-04 18:03:50 +02:00
### Deploy Mailu on the docker swarm
2018-08-04 17:58:53 +02:00
Run the following command:
```bash
docker stack deploy -c docker-compose-stack.yml mailu
```
See how the services are being deployed:
```bash
core@coreos-01 ~ $ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ywnsetmtkb1l mailu_antivirus replicated 1/1 mailu/none:1.5
pqokiaz0q128 mailu_fetchmail replicated 1/1 mailu/fetchmail:1.5
```
check a specific service:
```bash
core@coreos-01 ~ $ docker service ps mailu_fetchmail
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
tbu8ppgsdffj mailu_fetchmail.1 mailu/fetchmail:1.5 coreos-01 Running Running 11 days ago
```
### Remove the stack
Run the follwoing command:
```bash
core@coreos-01 ~ $ docker stack rm mailu
```