Skip to content

Commit

Permalink
Added docker compose file customizable from a .env file.
Browse files Browse the repository at this point in the history
Signed-off-by: Exadra37 <[email protected]>
  • Loading branch information
Exadra37 committed Jan 21, 2018
1 parent 5001ac0 commit b0e3c47
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 43 deletions.
58 changes: 58 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# DOCKER COMPOSER CUSTOMIZATION
#

# Exim version needs to be the correct one for the required Alpine version
ALPINE_VERSION=3.7
EXIM_VERSION=4.89.1-r0

# Useful to build the docker image from other path
EXIM_IMAGE_BUILD_CONTEXT=.

# Builds a local docker image with the whatsoever name we want
# The EXIM_VERSION will be auto appended to the name:
# bambucha/exim-relay-local:4.89.1-r0
EXIM_IMAGE=bambucha/exim-relay-local

# Default port map is 25:25 but we can override it at any time as suit us
EXIM_PORT_MAP=2525:25

# By default a native docker volume is used with name smpt-dkim mapping to
# container dir /dkim.
#
# Docker volumes are suitable for heavy workloads, thus a normal host volume is
# the preferred approach for that scenarios.
#
# To use a host volume like /home/username/.exim/storage/dkim we need to create
# it with:
# $ mkdir -p /home/username/.exim/storage/dkim
# $ sudo chown 100:101 /home/username/.exim/storage/dkim
#
# The use of UID:GID as 100:101 is to match the ones used by the exim user on
# the container.
#
# Now use it just uncomment the below line and replace username with your host user.
#DKIM_VOLUME=/home/username/.exim/storage/dkim

# So if we have a domain like example.com we want to set this to:
HOSTNAME=mail.example.com


#
# DOCKER CONTAINER ENVIRONMENT
#

# REQUIRED
DKIM_DOMAINS=example.com

# Custimize here the ips or range of ips from where Exim is allowed to relay.
RELAY_FROM_HOSTS=10.0.0.0/8:172.16.0.0/12

# Customize the size used by OpenSSL to generate the DKIM key
DKIM_KEY_SIZE=2048

# Customize here the the headers to be used in the DKIM signature.
DKIM_SIGN_HEADERS=Date:From:To:Subject:Message-ID

# https://www.emailarchitect.net/domainkeys/doc/html/selector.htm
DKIM_SELECTOR=dkim
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
27 changes: 18 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
FROM alpine:3.6
ARG ALPINE_VERSION=3.7

FROM alpine:$ALPINE_VERSION
MAINTAINER Dmitry Prazdnichnov <[email protected]>

ARG VERSION=4.89-r5
ARG EXIM_VERSION=4.89.1-r0

ARG DKIM_DOMAINS=domain.tld
ARG RELAY_FROM_HOSTS=10.0.0.0/8:172.16.0.0/12:192.168.0.0/16
ARG DKIM_KEY_SIZE=1024
ARG DKIM_SELECTOR=dkim
ARG DKIM_SIGN_HEADERS=Date:From:To:Subject:Message-ID

LABEL org.label-schema.version=$VERSION \
LABEL org.label-schema.version=${EXIM_VERSION} \
org.label-schema.vcs-url=https://github.com/bambocher/docker-exim-relay \
org.label-schema.license=MIT \
org.label-schema.schema-version=1.0

ENV RELAY_FROM_HOSTS=10.0.0.0/8:172.16.0.0/12:192.168.0.0/16 \
DKIM_KEY_SIZE=1024 \
DKIM_SELECTOR=dkim \
DKIM_SIGN_HEADERS=Date:From:To:Subject:Message-ID
ENV RELAY_FROM_HOSTS=${RELAY_FROM_HOSTS} \
DKIM_DOMAINS=${DKIM_DOMAINS} \
DKIM_KEY_SIZE=${DKIM_KEY_SIZE} \
DKIM_SELECTOR=${DKIM_SELECTOR} \
DKIM_SIGN_HEADERS=${DKIM_SIGN_HEADERS}

RUN apk --no-cache add exim=$VERSION libcap openssl \
&& mkdir /dkim /var/log/exim /usr/lib/exim /var/spool/exim \
RUN apk --no-cache add exim=${EXIM_VERSION} libcap openssl \
&& mkdir -p /dkim /var/log/exim /usr/lib/exim /var/spool/exim \
&& ln -s /dev/stdout /var/log/exim/main \
&& ln -s /dev/stderr /var/log/exim/panic \
&& ln -s /dev/stderr /var/log/exim/reject \
Expand Down
82 changes: 48 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
Create docker volume for dkim keys:

```shell
docker volume create --name=smtp-dkim
sudo docker volume create --name=smtp-dkim
```

Create docker container:

```shell
docker run \
sudo docker run \
-d \
--name smtp \
--restart=always \
Expand All @@ -29,27 +29,41 @@ docker run \

## [Docker Compose](https://docs.docker.com/compose/compose-file)

```yml
version: "2"
services:
smtp:
restart: always
image: bambucha/exim-relay
user: exim
ports:
- "25:25"
volumes:
- smtp-dkim:/dkim
hostname: mail.example.com
environment:
- RELAY_FROM_HOSTS=10.0.0.0/8:172.16.0.0/12:192.168.0.0/16
- DKIM_KEY_SIZE=1024
- DKIM_SELECTOR=dkim
- DKIM_SIGN_HEADERS=Date:From:To:Subject:Message-ID
- DKIM_DOMAINS=example.com
volumes:
smtp-dkim:
driver: local
Please rename `.env-example` to `.env` in order to customize how to build the
image and containers to run Exim from Docker.

The `.env` file contains comments explaining how each parameter in the
`docker-compose.yml` can be overridden.


#### Run Exim on the background

```shell
sudo docker-compose up -d smtp
```

#### Run Exim attached to the Shell

```shell
sudo docker-compose up smtp
```

#### Destroy the running Exim container

```
sudo docker-compose down
```

#### Access the Shell of the running container

```shell
sudo docker-compose exec smtp /bin/sh
```

#### Access the Shell without having a container running

```shell
sudo docker-compose run -u root --entrypoint=/bin/sh --rm smtp
```

## Reverse PTR
Expand All @@ -73,13 +87,13 @@ example.com. 300 IN TXT "v=spf1 a mx -all"
Get dkim public key with docker exec:

```shell
docker exec -it smtp cat /dkim/example.com.pub
sudo docker exec -it smtp cat /dkim/example.com.pub
```

or get dkim public key with docker-compose exec:

```shell
docker-compose exec smtp cat /dkim/example.com.pub
sudo docker-compose exec smtp cat /dkim/example.com.pub
```

or get dkim public key from docker volume:
Expand All @@ -99,25 +113,25 @@ dkim._domainkey.example.com. 300 IN TXT "v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GN
Print a count of the messages in the queue:

```shell
docker exec -it smtp exim -bpc
sudo docker exec -it smtp exim -bpc
```

Print a listing of the messages in the queue (time queued, size, message-id, sender, recipient):

```shell
docker exec -it smtp exim -bp
sudo docker exec -it smtp exim -bp
```

Remove all frozen messages:

```shell
docker exec -it smtp exim -bpu | grep frozen | awk {'print $3'} | xargs exim -Mrm
sudo docker exec -it smtp exim -bpu | grep frozen | awk {'print $3'} | xargs exim -Mrm
```

Test how exim will route a given address:

```shell
docker exec -it smtp exim -bt [email protected]
sudo docker exec -it smtp exim -bt [email protected]
```

```
Expand All @@ -133,31 +147,31 @@ [email protected]
Display all of Exim's configuration settings:

```shell
docker exec -it smtp exim -bP
sudo docker exec -it smtp exim -bP
```

View a message's headers:

```shell
docker exec -it smtp exim -Mvh <message-id>
sudo docker exec -it smtp exim -Mvh <message-id>
```

View a message's body:

```shell
docker exec -it smtp exim -Mvb <message-id>
sudo docker exec -it smtp exim -Mvb <message-id>
```

View a message's logs:

```shell
docker exec -it smtp exim -Mar <message-id>
sudo docker exec -it smtp exim -Mar <message-id>
```

Remove a message from the queue:

```shell
docker exec -it smtp exim -Mrm <message-id> [ <message-id> ... ]
sudo docker exec -it smtp exim -Mrm <message-id> [ <message-id> ... ]
```

Send a message:
Expand Down
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "2.1"

services:
smtp:
restart: always
build:
context: ${EXIM_IMAGE_BUILD_CONTEXT:-.}
args:
ALPINE_VERSION: ${ALPINE_VERSION:-3.7}
EXIM_VERSION: ${EXIM_VERSION:-4.90}
image: ${EXIM_IMAGE:-bambucha/exim-relay}:${EXIM_VERSION:-4.90}
ports:
- ${EXIM_PORT_MAP:-25:25}
volumes:
- ${DKIM_VOLUME:-smtp-dkim}:/dkim
hostname: ${HOSTNAME:-mail.domain.tld}
environment:
DKIM_DOMAINS: ${DKIM_DOMAINS:-domain.tld}
RELAY_FROM_HOSTS: ${RELAY_FROM_HOSTS:-10.0.0.0/8:172.16.0.0/12:192.168.0.0/16}
DKIM_KEY_SIZE: ${DKIM_KEY_SIZE:-1024}
DKIM_SELECTOR: ${DKIM_SELECTOR:-dkim}
DKIM_SIGN_HEADERS: ${DKIM_SIGN_HEADERS:-Date:From:To:Subject:Message-ID}

volumes:
smtp-dkim:
driver: local

0 comments on commit b0e3c47

Please sign in to comment.