How to Create an Email with Your Own Domain on a VPS?

To set up your own email hosting using Docker on a VPS, follow these steps:

Step 1: Get Docker Image

Get the latest image of the "Docker Mail Server" from the official Docker Hub registry or from the GitHub registry. You can do this using the command:

docker pull mailserver/docker-mailserver

Step 2: Configure Docker Compose

Create a YAML file named docker-compose.yml in the directory where you want to store your mail server configuration files. This file should contain the following content for a basic configuration of the mail server:

version: '3.8'
    container_name: mailserver
    hostname: mail-server
      - "25:25"
      - "587:587"
      - "465:465"
      - ./docker-data/dms/mail-data/:/var/mail/
      - ./docker-data/dms/mail-state/:/var/mail-state/
      - ./docker-data/dms/mail-logs/:/var/log/mail/
      - ./docker-data/dms/config/:/tmp/docker-mailserver/

Step 3: Release Ports

Release the necessary ports on your VPS's firewall to allow incoming connections to your mail server. For example, if you are using UFW, you can open the ports with the command:

sudo ufw allow 25,143,165,587,993/tcp

Step 4: Apply Hostname to DNS Settings

Apply the hostname and domain name specified in your docker-compose.yml file to your DNS settings. This is important for setting up secure authentication and for sending emails.

Step 5: Generate DKIM and DMARC Records

Generate DKIM and DMARC records according to the instructions provided in the Docker Mail Server documentation. These records are necessary for preventing email spoofing and verifying email senders.

Step 6: Start Server and Create First Address

Start the configured mail server directly from the registry with the command:

docker-compose up

Create the first email address using the command:

./ email add user@domain password

Additional Configuration

You can further customize your mail server by creating additional profiles, setting up spam filters, and configuring other features as needed.


Setting up your own email hosting using Docker on a VPS involves several steps, including getting the Docker image, configuring Docker Compose, releasing ports, applying the hostname to DNS settings, generating DKIM and DMARC records, starting the server, and creating the first email address. By following these steps, you can have a fully functional email hosting service that you can manage and customize according to your needs.

Citations: [1] [2] [3] [4] [5]