I am aware that Mailcow team doesn’t provide support and advise to use LXC container to run a mailcow dockerized version.
But accept community usage without support for them ! (mailcow/mailcow-dockerized4215)
It’s important to have access to the hypervisor, so you can’t use LXC for VPS provider ! But your own server with LXC VMs on it.
But in some case (mine for example) is mandatory. The ressource of the hardware that going to run the VPS is not enought for a full KVM machine.
I finnaly manage to succesfully run mailcow January Update 2022 on in a unprivileged LXC container with Proxmox.
You may need to modify some configuration, the max number of process for dovecot docker for example.
I - Prepare your proxmox hypervisor
Loging into your proxmox hypervisor.
Need to load overlay and naufs module on proxmox :
echo -e “overlay\naufs” >> /etc/modules-load.d/modules.conf
Install cgroups-mount (don’t really knwon if finally need but it’s done in my case) :
apt-get install cgroups-mount
reboot
II - Prepare a unprivileged LXC container
I choose to use debian-11-standard_11.0-1_amd64 as CT template.
Make a new container, as usual via the proxmox GUI. My basic configuration was :
arch: amd64
cores: 2
hostname: mail.domain.wan
memory: 6144
net0: name=eth0,bridge=vmbr0,firewall=1,gw=192.168.0.254,hwaddr=B2:F9:44:FB:4E:EC,ip=192.168.0.4/24,type=veth
ostype: debian
rootfs: local:102/vm-102-disk-0.raw,size=60G
swap: 2048
unprivileged: 1
Loging into your VPS (LXC container just created).
Be sure to be with the last version of all your system :
apt-get update
apt-get upgrade
apt-get dist-upgrade
Configure your timezone :
dpkg-reconfigure tzdata
I choose to remove postfix and use msmtp (a smtp client) to manage local mail of the container.
For the cron task and other system app who want to send me a mail !
That’s going to let free the port 25 of the LXC container (localy).
apt-get purge postfix
apt-get install msmtp-mta (be carefull, use msmtp-mta, not only msmtp because msmtp-mta include a sendmail emulation)
Edit the config file,and paste the line below to it, of msmtp with :
nano /etc/msmtprc
I use gmail to manage system email, of course don’t use email for mailcow because if you have some issue on it, you will not
be advise by the system. I choose gmail by IMAP (by sure to enable less secure apps on Gmail for IMAP).
This is my config of msmtp (change USERNAME and PASSWORD) :
#account default
defaults
account default
auth on
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /var/log/msmtp.log
host smtp.gmail.com
port 587
from USERNAME@gmail.com
user USERNAME@gmail.com
password PASSWORD
aliases /etc/aliases
Now, we going to install a command line mail client :
apt-get install bsd-mailx
Edit your aliases files, with
nano /etc/aliases
This is my aliases file you need to personnalize with your mail :
postmaster: root
webmaster: root
root: USERNAME@gmail.com
local: USERNAME@gmail.com
default: USERNAME@gmail.com
And finally, secure a little bit your LXC container with a mail each time someone log to your system (My TIPS). Edit bash config :
nano /etc/bash.bashrc
And add this line at the end of the file :
echo ‘ALERT - Shell Access on: ’ `date` `who` | mail -s “Alert: Shell Access on `hostname -f`” root
If you log out, and loging again, you should receive a mail with this alert. Great, everything seems to work.
If not, take a look on /var/log/msmtp.log to debug.
OPTION (just for daily backup cronjob, see https://mailcow.github.io/mailcow-dockerized-docs/backup_restore/b_n_r-backup/) :
I choose to share my BACKUP storage of my proxmox (a external NAS) with my mailcow LXC container. This is the storage where I put of my VM backup with vzdump on Proxmox.
I will add a crontask to manage a daily backup of my data, so I have to make a local mount folder :
mkdir /mnt/NAS
chmod 777 /mnt/NAS
The VPS is almost done now, stop with :
halt
Now add this configuration in the proxmox LXC config, add the end of the file (/etc/pve/lxc/VMID.conf on a proxmox shell) :
lxc.apparmor.profile: unconfined
lxc.cgroup.devices.allow: a
lxc.cap.drop:
#OPTION for daily cronjob, should be personnalize with your own storage
lxc.mount.entry: /mnt/pve/NAS mnt/NAS/ none rw,bind 0 0
You can now run again your VPS, we are ready to install mailcow !
III - Mailcow installation
Boot your VPS, and login into to again and follow the installation documentation : https://mailcow.github.io/mailcow-dockerized-docs/i_u_m/i_u_m_install/
At the step 5, don’t run “docker-compose up -d”, we going to modify some config before.
Edit /opt/mailcow-dockerized/docker-compose.yml with :
nano /opt/mailcow-dockerized/docker-compose.yml
In redis-mailcow section, comment/remove thoses lines (https://community.mailcow.email/d/1054-sysctl-for-redis-breaks-on-lxclcd/2)
# sysctls:
# - net.core.somaxconn=4096
For us, it’s totally useless, because on 5.4 kernel (it’s the case of proxmox 6.4-13 somaxconn is already 4096 but docker in LXC does’nt support this option).
Finally in dovecot-mailcow section, modify nproc limits
ulimits :
nproc: 30000 #(Instead of 65535)
Not a big deal on a home usage even for more, it’s limit the number of process inside the dovecot docker.
You should now run :
docker-compose up -d
Mailcow-dockerized version should run now just fine, you are ready to finalize your mailcow configuration !
Don’t forget, if you choose the option, to make the cronjob for daily bakcup (https://mailcow.github.io/mailcow-dockerized-docs/backup_restore/b_n_r-backup/)
Enjoy !