|
| 1 | +Docker installation |
| 2 | +=================== |
| 3 | + |
| 4 | +This section provides instructions for installing a chatmail relay |
| 5 | +using Docker Compose. |
| 6 | + |
| 7 | +.. note:: |
| 8 | + |
| 9 | + Docker support is experimental and not yet covered by automated tests, please report bugs. |
| 10 | + |
| 11 | + |
| 12 | +Known limitations |
| 13 | +----------------- |
| 14 | + |
| 15 | +- Requires cgroups v2 on the host. Operation with cgroups v1 has not been tested. |
| 16 | +- This preliminary image simply wraps the cmdeploy process detailed in the :doc:`getting_started` instructions in a full Debian-systemd image. |
| 17 | +- Currently, the image has only been tested and built on amd64, though arm64 should theoretically work as well. |
| 18 | + |
| 19 | + |
| 20 | +Prerequisites |
| 21 | +------------- |
| 22 | + |
| 23 | +- **Docker Compose v2** (``docker compose``, not ``docker-compose``) is |
| 24 | + required for its ``cgroup: host`` support (`Install instructions <https://docs.docker.com/engine/install/debian/#install-using-the-repository>`_:) |
| 25 | + |
| 26 | +- **DNS records** for your domain (see step 1 below). |
| 27 | + |
| 28 | +- **Kernel parameters** — ``fs.inotify.max_user_instances`` and |
| 29 | + ``fs.inotify.max_user_watches`` must be raised on the host because they |
| 30 | + cannot be changed inside the container (see step 2 below). |
| 31 | + |
| 32 | + |
| 33 | +Preliminary setup |
| 34 | +----------------- |
| 35 | + |
| 36 | +We use ``chat.example.org`` as the chatmail domain in the following |
| 37 | +steps. Please substitute it with your own domain. |
| 38 | + |
| 39 | +1. Setup the initial DNS records. |
| 40 | + The following is an example in the familiar BIND zone file format with |
| 41 | + a TTL of 1 hour (3600 seconds). |
| 42 | + Please substitute your domain and IP addresses. |
| 43 | + |
| 44 | + :: |
| 45 | + |
| 46 | + chat.example.org. 3600 IN A 198.51.100.5 |
| 47 | + chat.example.org. 3600 IN AAAA 2001:db8::5 |
| 48 | + www.chat.example.org. 3600 IN CNAME chat.example.org. |
| 49 | + mta-sts.chat.example.org. 3600 IN CNAME chat.example.org. |
| 50 | + |
| 51 | +2. Configure kernel parameters on the host, as these can not be set from the container:: |
| 52 | + |
| 53 | + echo "fs.inotify.max_user_instances=65536" | sudo tee -a /etc/sysctl.d/99-inotify.conf |
| 54 | + echo "fs.inotify.max_user_watches=65536" | sudo tee -a /etc/sysctl.d/99-inotify.conf |
| 55 | + sudo sysctl --system |
| 56 | + |
| 57 | + |
| 58 | +Docker Compose Setup |
| 59 | +-------------------- |
| 60 | + |
| 61 | +Pre-built images are available from GitHub Container Registry. The |
| 62 | +``main`` branch and tagged releases are pushed automatically by CI:: |
| 63 | + |
| 64 | + docker pull ghcr.io/chatmail/relay:main # latest main branch |
| 65 | + docker pull ghcr.io/chatmail/relay:1.2.3 # tagged release |
| 66 | + |
| 67 | + |
| 68 | +Create service directory |
| 69 | +^^^^^^^^^^^^^^^^^^^^^^^^ |
| 70 | + |
| 71 | +Either: |
| 72 | + |
| 73 | +- Create a service directory, e.g., `/srv/chatmail-relay`:: |
| 74 | + |
| 75 | + mkdir -p /srv/chatmail-relay && cd /srv/chatmail-relay |
| 76 | + wget https://raw.githubusercontent.com/chatmail/relay/refs/heads/main/docker-compose.yaml https://raw.githubusercontent.com/chatmail/relay/refs/heads/main/docker-compose.override.yaml.example |
| 77 | + wget https://raw.githubusercontent.com/chatmail/relay/refs/heads/main/docker/env.example -O .env |
| 78 | + |
| 79 | + |
| 80 | +- or clone the chatmail repo :: |
| 81 | + |
| 82 | + git clone https://github.com/chatmail/relay |
| 83 | + cd relay |
| 84 | + cp example.env .env |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +Customize and start |
| 89 | +^^^^^^^^^^^^^^^^^^^ |
| 90 | + |
| 91 | +1. All local customizations (data paths, extra volumes, config mounts) go in |
| 92 | + ``docker-compose.override.yaml``, which Compose merges automatically with |
| 93 | + the base file. By default, all data is stored in docker volumes, you will |
| 94 | + likely want to at least create and configure the mail storage location. Copy |
| 95 | + the example to get started:: |
| 96 | + |
| 97 | + cp docker/docker-compose.override.yaml.example docker-compose.override.yaml |
| 98 | + # and edit docker-compose.override.yaml |
| 99 | + |
| 100 | + |
| 101 | +2. Configure the ``.env`` file. Only ``MAIL_DOMAIN`` is required, the domain |
| 102 | + name of the future server. |
| 103 | + |
| 104 | + The container generates a ``chatmail.ini`` with defaults from |
| 105 | + ``MAIL_DOMAIN`` on first start. To customize chatmail settings, mount |
| 106 | + your own ``chatmail.ini`` instead (see `Custom chatmail.ini`_ below). |
| 107 | + |
| 108 | +3. Start the container:: |
| 109 | + |
| 110 | + docker compose up -d |
| 111 | + docker compose logs -f chatmail # view logs, Ctrl+C to exit |
| 112 | + |
| 113 | +4. After installation is complete, open ``https://chat.example.org`` in |
| 114 | + your browser. |
| 115 | + |
| 116 | + |
| 117 | +Managing the server |
| 118 | +------------------- |
| 119 | + |
| 120 | +Use ``docker exec`` to run cmdeploy commands inside the container:: |
| 121 | + |
| 122 | + # Show required DNS records |
| 123 | + docker exec chatmail /opt/cmdeploy/bin/cmdeploy dns --ssh-host @local |
| 124 | + |
| 125 | + # Check server status |
| 126 | + docker exec chatmail /opt/cmdeploy/bin/cmdeploy status --ssh-host @local |
| 127 | + |
| 128 | + # Run benchmarks (can also run from any machine with cmdeploy installed) |
| 129 | + docker exec chatmail /opt/cmdeploy/bin/cmdeploy bench chat.example.org |
| 130 | + |
| 131 | + |
| 132 | +Customization |
| 133 | +------------- |
| 134 | + |
| 135 | +Custom website |
| 136 | +^^^^^^^^^^^^^^ |
| 137 | + |
| 138 | +You can customize the chatmail landing page by mounting a directory with |
| 139 | +your own website source files. |
| 140 | + |
| 141 | +1. Create a directory with your custom website source:: |
| 142 | + |
| 143 | + mkdir -p ./custom/www/src |
| 144 | + nano ./custom/www/src/index.md |
| 145 | + |
| 146 | +2. Add the volume mount in ``docker-compose.override.yaml``:: |
| 147 | + |
| 148 | + services: |
| 149 | + chatmail: |
| 150 | + volumes: |
| 151 | + - ./custom/www:/opt/chatmail-www |
| 152 | + |
| 153 | +3. Restart the service:: |
| 154 | + |
| 155 | + docker compose down |
| 156 | + docker compose up -d |
| 157 | + |
| 158 | + |
| 159 | +Custom chatmail.ini |
| 160 | +^^^^^^^^^^^^^^^^^^^ |
| 161 | + |
| 162 | +There are two configuration modes: |
| 163 | + |
| 164 | +**Simple (default):** Set ``MAIL_DOMAIN`` in ``.env``. The container |
| 165 | +auto-generates ``chatmail.ini`` with defaults on first start. This is |
| 166 | +sufficient for most deployments. |
| 167 | + |
| 168 | +**Advanced:** Generate a ``chatmail.ini``, edit it, and mount it into |
| 169 | +the container. This gives you full control over all chatmail settings. |
| 170 | + |
| 171 | +1. Extract the generated config from a running container:: |
| 172 | + |
| 173 | + docker cp chatmail:/etc/chatmail/chatmail.ini ./chatmail.ini |
| 174 | + |
| 175 | +2. Edit ``chatmail.ini`` as needed. |
| 176 | + |
| 177 | +3. Add the volume mount in ``docker-compose.override.yaml`` :: |
| 178 | + |
| 179 | + services: |
| 180 | + chatmail: |
| 181 | + volumes: |
| 182 | + - ./chatmail.ini:/etc/chatmail/chatmail.ini |
| 183 | + |
| 184 | +4. Restart the container, the container skips generating a new one: :: |
| 185 | + |
| 186 | + docker compose down && docker compose up -d |
| 187 | + |
| 188 | + |
| 189 | +Migrating from a bare-metal install |
| 190 | +------------------------------------ |
| 191 | + |
| 192 | +If you have an existing bare-metal chatmail installation and want to |
| 193 | +switch to Docker: |
| 194 | + |
| 195 | +1. Stop all existing services:: |
| 196 | + |
| 197 | + systemctl stop postfix dovecot doveauth nginx opendkim unbound \ |
| 198 | + acmetool-redirector filtermail filtermail-incoming chatmail-turn \ |
| 199 | + iroh-relay chatmail-metadata lastlogin mtail |
| 200 | + systemctl disable postfix dovecot doveauth nginx opendkim unbound \ |
| 201 | + acmetool-redirector filtermail filtermail-incoming chatmail-turn \ |
| 202 | + iroh-relay chatmail-metadata lastlogin mtail |
| 203 | + |
| 204 | +2. Copy your existing ``chatmail.ini`` and mount it into the container |
| 205 | + (see `Custom chatmail.ini`_ above):: |
| 206 | + |
| 207 | + cp /usr/local/lib/chatmaild/chatmail.ini ./chatmail.ini |
| 208 | + |
| 209 | +3. Copy persistent data into the ``./data/`` subdirectories (for example, as configured in `Customize and start`_) :: |
| 210 | + |
| 211 | + mkdir -p data/chatmail-dkimkeys data/chatmail-acme data/chatmail |
| 212 | + |
| 213 | + # DKIM keys |
| 214 | + cp -a /etc/dkimkeys/* data/chatmail-dkimkeys/ |
| 215 | + |
| 216 | + # ACME certificates and account |
| 217 | + rsync -a /var/lib/acme/ data/chatmail-acme/ |
| 218 | + |
| 219 | + # Mail data |
| 220 | + rsync -a /home/ data/chatmail/ |
| 221 | + |
| 222 | + Alternatively, mount ``/home/vmail`` directly by changing the volume |
| 223 | + in ``docker-compose-override.yaml``:: |
| 224 | + |
| 225 | + - /home/vmail:/home/vmail |
| 226 | + |
| 227 | + The three ``./data/`` subdirectories cover all persistent state. |
| 228 | + Everything else is regenerated by the ``configure`` and ``activate`` |
| 229 | + stages on container start. |
| 230 | + |
| 231 | +Building the image |
| 232 | +------------------ |
| 233 | + |
| 234 | +Clone the repository and build the Docker image:: |
| 235 | + |
| 236 | + git clone https://github.com/chatmail/relay |
| 237 | + cd relay |
| 238 | + docker compose build chatmail |
| 239 | + |
| 240 | +The build bakes all binaries, Python packages, and the install stage |
| 241 | +into the image. After building, only ``docker-compose.yaml`` and ``.env`` |
| 242 | +are needed to run the container. |
| 243 | + |
| 244 | +You can transfer a locally built image to your server directly (pigz is parallel `gzip` which can be used instead as well) :: |
| 245 | + |
| 246 | + docker save chatmail-relay:latest | pigz | ssh chat.example.org 'pigz -d | docker load' |
| 247 | + |
| 248 | + |
| 249 | +Forcing a full reinstall |
| 250 | +------------------------ |
| 251 | + |
| 252 | +On container start, only the ``configure`` and ``activate`` stages run by default. |
| 253 | + |
| 254 | +To force a full reinstall (e.g. after updating the source), either |
| 255 | +rebuild the image:: |
| 256 | + |
| 257 | + docker compose build chatmail |
| 258 | + docker compose up -d |
| 259 | + |
| 260 | +Or override the stages at runtime without rebuilding:: |
| 261 | + |
| 262 | + CMDEPLOY_STAGES="install,configure,activate" docker compose up -d |
0 commit comments