FROM alpine:3.20

RUN apk add --no-cache dovecot dovecot-pop3d dovecot-pgsql

RUN addgroup -g 1000 vmail && adduser -D -u 1000 -G vmail -h /var/mail vmail

RUN mkdir -p /var/log/dovecot /var/mail/vhosts /run/dovecot && \
    chown -R vmail:vmail /var/mail && \
    chown -R dovecot:dovecot /var/log/dovecot /run/dovecot

COPY dovecot.conf /etc/dovecot/dovecot.conf
COPY dovecot-sql.conf /etc/dovecot/dovecot-sql.conf

RUN chmod 600 /etc/dovecot/dovecot-sql.conf

EXPOSE 143 110

CMD ["dovecot", "-F"]
