This project is an addon for the Docker Mailserver (DMS) project. It provides a simple web interface to manage email aliases. This addon is packaged as a Docker container that hosts a REST API written in Go and a frontend built with Svelte, Tailwind CSS, and DaisyUI.
To run the Docker container, you will need:
You can change the port of the web server with the following environment variable:
export GIN_ADDR=":8080"
Add the mailserver-aliases
container to your docker-compose.yaml
file:
services:
mailserver-aliases:
image: chscheid/docker-mailserver-aliases:1.0.1
restart: unless-stopped
read_only: true
ports:
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
cap_drop:
- ALL
Note: There is no built-in authentication for the frontend, so the web interface will be publicly available under port 8080. You may want to secure it with a reverse proxy and authentication.
Mounting the Docker socket into the container is required for this project because the container needs to communicate with the Docker daemon to manage email aliases on the Docker Mailserver. The Docker Engine SDK is used to interact with the Docker daemon, allowing the REST API to list, add, and delete aliases.
While mounting the Docker socket (/var/run/docker.sock
) into a container grants the container elevated permissions to interact with the Docker daemon, it is a common practice for tools that need to manage Docker containers. Here are some considerations to ensure this setup remains secure:
--cap-drop
option to limit the container’s capabilities.Here is an example to serve the frontend with Caddy and Basic Authentication:
docker-compose.yaml
:
services:
caddy:
image: caddy:2.8
restart: unless-stopped
environment:
- FRONTEND_BASIC_AUTH_USER="username"
- FRONTEND_BASIC_AUTH_PASSWORD="HASHED_PASSWORD"
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
mailserver-aliases:
image: chscheid/docker-mailserver-aliases:1.0.1
read_only: true
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
cap_drop:
- ALL
Caddyfile
:
aliases.yourdomain.com {
basic_auth {
{$FRONTEND_BASIC_AUTH_USER} {$FRONTEND_BASIC_AUTH_PASSWORD}
}
reverse_proxy mailserver-aliases:8080
}
Replace username
and HASHED_PASSWORD
with your values. For more information on configuring Caddy and hashing the password, see the Caddy documentation.
To develop and contribute to this project, you can run both the backend and frontend locally. You can mock the API for frontend development using Mockoon.
The backend REST API is written in Go and provides endpoints to manage aliases. It interacts with the Docker Mailserver instance through the Docker Engine API.
To start the development server for the backend:
go run main.go
The Swagger documentation is generated with Swag.
Generate the documentation with:
swag init
You can view the documentation at:
http://localhost:8080/docs/index.html
The frontend is built with Svelte, Tailwind CSS, and daisyUI. It communicates with the backend REST API to manage email aliases.
To run the frontend locally, follow these steps:
Navigate to the frontend
directory:
cd ./frontend
Install the necessary dependencies:
npm install
Use Mockoon to mock the REST API if the Docker Mailserver is not running:
npm run mockoon
Start the frontend development server:
npm run dev
This will start the frontend on http://localhost:5173/.
Contributions are welcome! If you'd like to contribute to the project, please follow these steps:
git checkout -b feature-branch
).git commit -am 'Add new feature'
).git push origin feature-branch
).Please make sure to update tests as appropriate.
One of the goals for future development of this project is to eliminate the need to mount the Docker socket (/var/run/docker.sock
) into the container. Although mounting the Docker socket is currently required for the REST API to interact with the Docker Mailserver, this practice can pose security risks.
This project is open-source and available under the MIT License.