sumarsono.com
Take it with a grain of salt


Docker Compose: Traefik Ghost Mysql Docker Compose

Posted on

Create internal docker network and public docker network:

docker network create internal-network;
docker network create proxy-network;

Traefik docker-compose.yaml

mkdir ~/traefik;
cd ~/traefik;
cat <<yaml > docker-compose.yaml
version: "3.8"

services:
  traefik:
    image: "traefik:v2.5"
    container_name: "traefik"
    restart: unless-stopped
    command:
      #- "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entryPoints.web.forwardedHeaders.insecure"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    networks:
      - proxy-network
    labels:
      - "traefik.docker.network=proxy-network"
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 50M
        reservations:
          cpus: '0.25'
          memory: 20M

networks:
  proxy-network:
    external: true
yaml

docker-compose up -d

MySQL docker-compose.yaml

mkdir ~/mysql;
cd ~/mysql;
cat <<yaml > docker-compose.yaml
version: '3.8'

services:
  db-mysql8:
    container_name: mysql8
    image: mysql/mysql-server:8.0.28-1.2.7-server
    command: mysqld --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: "yourrootstrongpasswd"
      MYSQL_DATABASE: "ghost_db"
      MYSQL_USER: "ghost_user"
      MYSQL_PASSWORD: "ghost_passwd"
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
    ports:
      - '3306:3306'
    volumes:
      - './db/data:/var/lib/mysql'
      - './db/my.cnf:/etc/mysql/conf.d/my.cnf'
      - './db/sql:/docker-entrypoint-initdb.d'
    networks:
      - internal-network

networks:
  internal-network:
    external: true
yaml

docker-compose up -d;

Ghost docker-compose.yaml

mkdir ~/ghost;
cd ~/ghost;
cat <<yaml > docker-compose.yaml
version: '3.8'
services:
  ghost:
    image: 'ghost:4.32-alpine'
    container_name: ghost-service
    volumes:
      - '/home/sumar/ghost/data:/var/lib/ghost/content'
    restart: unless-stopped
    environment:
      url: http://ghost.domain.com
      mail__from: noreply-ghost@domain.com
      mail__transport: SMTP
      mail__options__host: your-smtp.com
      mail__options__port: 465
      mail__options__service: SES
      mail__options__auth__user: your-smtp-user
      mail__options__auth__pass: your-smtp-passwd
      database__client: mysql
      database__connection__host: db-mysql8
      database__connection__user: ghost_user
      database__connection__password: ghost_db
      database__connection__database: ghost_passwd
    networks:
      - proxy-network
      - internal-network
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=proxy-network"
      - "traefik.http.routers.ghost.rule=Host(`ghost.domain.com`)"
      - "traefik.http.routers.ghost.entrypoints=web"

networks:
  proxy-network:
    external: true
  internal-network:
    external: true
yaml

docker-compose up -d;