Introduction:

In this guide, we'll walk you through setting up Ghost, MySQL, and Caddy using three separate Docker Compose files. We'll utilize two different networks for our setup, one for the public-facing Caddy reverse proxy, and another for private communication between Ghost and MySQL. This efficient deployment method enables better manageability and scalability for your projects.

Step 1: Create Two Docker Networks

First, we need to create two Docker networks. One network will be for the Caddy reverse proxy (caddy-net), and the other will be for private communication between Ghost and MySQL (private-net). To create these networks, run the following commands:

docker network create caddy-net
docker network create private-net

Step 2: Set Up the MySQL Docker Compose File

Create a new file called mysql-compose.yml and add the following configuration:

version: "3.9"
services:
  mysql:
    image: mysql:latest
    container_name: mysql_container
    environment:
      MYSQL_ROOT_PASSWORD: your_root_password
    networks:
      - private-net

networks:
  private-net:
    external: true

Replace the placeholders with your actual database credentials.

Step 3: Set Up the Ghost Docker Compose File

Create a new file called ghost-compose.yml and add the following configuration:

version: "3.9"
services:
  ghost:
    image: ghost:latest
    container_name: ghost_container
    environment:
      database__client: mysql
      database__connection__host: mysql_container
      database__connection__user: root
      database__connection__password: your_root_password
      database__connection__database: your_database_name
      url: https://www.talz.net
      mail__transport: smtp
      mail__options__host: smtp.mailgun.org
      mail__options__port: 587
      mail__options__secureConnection: false
      mail__options__auth__user: postmaster@talz.net
      mail__options__auth__pass: your_mailgun_password
    networks:
      - private-net

networks:
  private-net:
    external: true

Replace the placeholders with the appropriate database credentials and your domain.

Step 4: Set Up the Caddy Docker Compose File

Create a new file called caddy-compose.yml and add the following configuration:

version: "3.9"
services:
  caddy:
    image: caddy:latest
    container_name: caddy_container
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - $PWD/site:/srv
      - ./caddy_data:/data
      - ./caddy_config:/config
    ports:
      - "80:80"
      - "443:443"
    networks:
      - caddy-net
      - private-net

networks:
  caddy-net:
    external: true
  private-net:
    external: true

Step 5: Create the Caddyfile

Create a new file called Caddyfile in the same directory as your caddy-compose.yml file and add the following configuration:

{ 
    email XXXX@gmail.com
    
}
www.talz.net {
    reverse_proxy ghost_container:2368 {
        lb_try_duration 30s
    }
}

talz.net {
    redir https://www.talz.net{uri}
}

Step 6: Deploy the Services

Now that all Docker Compose files are ready, deploy the services by running the following commands in the terminal:

docker-compose -f mysql-compose.yml up -d
docker-compose -f ghost-compose.yml up -d
docker-compose -f caddy-compose.yml up -d

Conclusion:

Congratulations! You've successfully set up Ghost, MySQL, and Caddy using separate Docker Compose files and two distinct networks. This configuration provides an efficient and scalable way to deploy and manage your services.