Files
mail-server/README.md
2025-06-12 14:16:02 +00:00

191 lines
5.6 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p align="center">
<a href="https://tip.jhammah.com">
<picture>
<img src="https://jhammah.com/wp-content/uploads/2025/06/Stalwart_logo1.png" alt="Caddy" width="500">
</picture>
</a>
</p>
<p align="center">
<a href="https://tip.jhammah.com">
<picture>
<img src="https://jhammah.com/wp-content/uploads/2025/06/Haproxy-logo.png" alt="Caddy" width="500">
</picture>
</a>
</p>
<p align="center">
<a href="https://tip.jhammah.com">
<picture>
<img src="https://jhammah.com/wp-content/uploads/2025/05/docker-icon.png" alt="Docker" width="175">
</picture>
</a>
</p>
<br>
<h1 align="center">Install Caddy with packages (xcaddy) inside Docker Desktop </h1>
<br>
<br>
# Navigation
- [Prerequisite](#prerequisite)
- [Install](#install)
- [Configuring docker-compose.yml file](#configuring-docker-composeyml-file)
- [Configuring .env file](#configuring-env-file)
- [Configuring dockerfile.caddy file](#configuring-dockerfilecaddy-file)
- [Configuring Caddyfile](#configuring-caddyfile)
- [Execute and finish](#execute-and-finish)
<br>
<br>
# Prerequisite
- **Here are all the things you need to make sure you have before starting this tutorial.**
- **1. You should already have Caddy installed and fully working.**
- **2. You should already have a Cloudflare account managing your domain.**
- **3. You should already have a Cloudflare API Token.**
- **4. You should already have the CNAME records 'mail.yourdomain.com' & 'webmail.yourdomain.com' created.**
- **5. You should already have your Caddyfile routing 'mail.yourdomain.com' to port 8404.**
- **6. You should already have your Caddyfile routing 'webmail.yourdomain.com' to port 680.**
- **7. You should already have an smtp2go.com account created and setup.**
- **8. You should use an advanced text editor like Notepadd++ or something like it that's designed for coding.**
- **9. You should already have ports 25, 80, 110, 143, 443, 465, 587, 993, & 4190 opened inside your router pointing to your host machine's IP address.**
<br>
<br>
# Install
<h4> This tutorial will show you how to install Stalwart Mail server as well as HAProxy so you can securely host your own email server. </h4>
<br>
<br>
<h3> 1</h3>
## Configuring docker-compose.yml file
* **This is the docker-compose.yml file that you will use to create your container. It will be installing HAProxy and then including Stalwart and Roundcube's yml files, installing them afterwards.**
* **It's always going to restart unless we manually stop it.**
* **We are mapping it to ports 25, 80, 110, 143, 443, 465, 587, 993, & 4190.**
* **We're also making HAProxy's container depend on Stalwart's container**
* **And finally we are creating a custom hao-network for these containers.**
<p align="center">
<a href="https://tip.jhammah.com">
<picture>
<img src="IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE " alt="Docker" width="1280">
</picture>
</a>
</p>
<br>
<br>
<h3> 2</h3>
## Configuring .env file
* **This is the .env file. Here you will want to enter your cloudflare API token as well as the email address you log into cloudflare with. This .env file will create variables that you can reference in your Caddyfile.**
<p align="center">
<a href="https://tip.jhammah.com">
<picture>
<img src="IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE " alt="Docker" width="1280">
</picture>
</a>
</p>
<br>
<br>
<h3> 3</h3>
## Configuring dockerfile.caddy file
* **This is the dockerfile.caddy file that your docker-compose.yml file will use to create your custom Caddy image.**
* **Inside this file, we're going to give it some commands to create the image from caddy:builder, include some GitHub packages, attach them to the caddy:latest.**
* **And then once it's built, copy it to a specific directory**
* **When you launch the docker-compose.yml file, it will trigger this file to build your custom image automatically.**
<p align="center">
<a href="https://tip.jhammah.com">
<picture>
<img src="IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE " alt="Docker" width="1280">
</picture>
</a>
</p>
<br>
<br>
<h3> 4</h3>
## Configuring Caddyfile
* **This is the Caddyfile. This file tells Caddy what and how to do things.**
* **Inside of the Caddyfile, I've organized it into three sections. Global, Snippets, and Sites.**
* **In the Global section, you're going to specify some default parameters .**
* **In the Snippets section, you're going to be creating variables and functions that you can import into your websites.**
* **Under the Site section, you will list your websites as well as commands for Caddy to perform on your website.**
<p align="center">
<a href="https://tip.jhammah.com">
<picture>
<img src="IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE IMAGE GOES HERE " alt="Docker" width="1280">
</picture>
</a>
</p>
<br>
<br>
# Execute and finish
**Once you have all of the files customized to your liking and all four of them are sitting in the same directory, you'll be ready to launch the yml file.**
**You can do this by right-clicking in an empty space in the folder where all your files are located and selecting 'Open in Terminal'.**
**That opens a Powershell window inside that direcotry where you can enter this code to launch everything.**
```ps1
docker-compose up -d
```
**And that's it! Caddy should be live ina Docker container and actively acting as a reverse proxy!**
<br>
<H1 align="center">Support the channel so I can make more tutorials!</h1>
<H1 align="center"><a href="https://tip.jhammah.com">If this tutorial helped you out, feel free to buy me a coffee!</h1>