Run Cyrus Imapd in a Docker container based on OpenSuSE Leap
# define a password for the mailserver administrator 'cyrus'
cyruspassword=password123
# Build and start the container cyrus-docker
docker-compose up -d --build
# Set the admin password for user cyrus
echo ${cyruspassword} |docker exec -i cyrus-docker saslpasswd2 -p -u cyrus -c cyrus
# at this point you have the mailbox server running
# you can check it with
docker ps
# Log in to it with bash (Note here we have -it whilst most other cmds have -i)
docker exec -it cyrus-docker bash
# tail the logs:
docker exec -i cyrus-docker tail -f /var/log/imapd.log /var/log/auth.log &
# or test that it is answering on port 143
nc -vz localhost 143
# or talk to with via imap protocol See RFC 3501.
telnet localhost 143
# first give a sequence number like a001 and then the command
# a001 login alice password1
# a002 list "" *
# a003 exit
# the above will not work before you create the mailboxes. See next:
# store the name and password in 2 shell variables to you can copy/paste the commands below
mailuser=alice
mailuserpassword=password1
# Create the user account
echo ${mailuserpassword} |docker exec -i cyrus-docker saslpasswd2 -p -u cyrus -c ${mailuser}
# Create the user mailbox:
docker exec -i cyrus-docker env TERM=dumb cyradm --user cyrus --password ${cyruspassword} --authz ${mailuser} --auth PLAIN localhost << CYRADMSCRIPT
createmailbox INBOX
subscribe INBOX
createmailbox INBOX.Archive
subscribe INBOX.Archive
listmailbox
listaclmailbox *
CYRADMSCRIPT
# Set quota for the mailbox none removes the quota or pass a value
docker exec -i cyrus-docker env TERM=dumb cyradm --user cyrus --password ${cyruspassword} --auth PLAIN localhost << CYRADMSCRIPT
setquota user.${mailuser} none
CYRADMSCRIPT
# Log in to the user mailbox with cyradm
docker exec -i cyrus-docker env TERM=dumb cyradm --user cyrus --password ${cyruspassword} --authz ${mailuser} --auth PLAIN localhost
# Log in to the admin account with cyradm
docker exec -i cyrus-docker env TERM=dumb cyradm --user cyrus --password ${cyruspassword} --auth PLAIN localhost
# List the users in the sasldb2 database:
docker exec -i cyrus-docker sasldblistusers2
# show the 3 background processes running in the container
docker exec -i cyrus-docker ps aux
# look at the configuration files:
docker exec -i cyrus-docker cat /etc/imapd.conf
docker exec -i cyrus-docker ls -l /etc/pam.d/
docker exec -i cyrus-docker cat /etc/pam.d/imap
docker exec -i cyrus-docker cat /etc/sysconfig/saslauthd
# This should succeed but fails:
docker exec -i cyrus-docker testsaslauthd -u alice -p password1 -f /run/sasl2/mux
# Ask Sasl about the available plugins
docker exec -i cyrus-docker pluginviewer
If you feel you want to have the mailbox stored outside the potentially short lived
container you can pass in the directory to use in the docker-compose.yml
file. Cyrus
Imapd stores the mailboxes in /var/lib/imap
and /var/spool/imap
.
# uncomment this and replace on the left side yout data directory
#volumes:
# - /richi/Privat/Data/Cyrus/lib/imap:/var/lib/imap
# - /richi/Privat/Data/Cyrus/spool/imap:/var/spool/imap
And when building the container and you already have data make sure to disable in the Dockerfile the following line:
# REMOVE THIS LINE IF YOU ARE CONNECTING TO EXISTING MAILBOXES
# initialise the mailboxes
RUN sudo -u cyrus /usr/lib/cyrus/tools/mkimap