docker-composeporttraefikghost-blog

Traefik ghost deployment port mapping NOT working


I used Dokploy to deploy a ghost blog instance with docker compose and traefik (reverse proxy). I have a problem accessing a ghost blog deployment from my browser: giving Bad Gateway error. If I use the default 2368 port of ghost deployment then everything works fine but if I use port mapping 3204:2368 to access it on a different port then I receive Bad Gateway error.

docker-compose.yml:

name: ghost-live-1
services:
  ghost:
    image: ghost:5-alpine
    container_name: ghost_serv_live_k
    restart: always
    environment:
      database__client: mysql
      database__connection__host: ghst_db
      database__connection__user: ghost
      database__connection__password: ghost
      database__connection__database: ghost
      url: https://blog.mydomain.com
      NODE_ENV: production
    ports:
      - '3204:2368'
    labels:
      - traefik.docker.network=dokploy-network
      - traefik.enable=true
      - traefik.http.routers.ghostlive-ghost-2e1bbd-50-web.rule=Host(`blog.mydomain.com`)
      - traefik.http.routers.ghostlive-ghost-2e1bbd-50-web.entrypoints=web
      - traefik.http.services.ghostlive-ghost-2e1bbd-50-web.loadbalancer.server.port=3204
      - traefik.http.routers.ghostlive-ghost-2e1bbd-50-web.service=ghostlive-ghost-2e1bbd-50-web
      - traefik.http.routers.ghostlive-ghost-2e1bbd-50-web.middlewares=redirect-to-https@file
      - traefik.http.routers.ghostlive-ghost-2e1bbd-50-websecure.rule=Host(`blog.mydomain.com`)
      - traefik.http.routers.ghostlive-ghost-2e1bbd-50-websecure.entrypoints=websecure
      - traefik.http.services.ghostlive-ghost-2e1bbd-50-websecure.loadbalancer.server.port=3204
      - traefik.http.routers.ghostlive-ghost-2e1bbd-50-websecure.service=ghostlive-ghost-2e1bbd-50-websecure
      - traefik.http.routers.ghostlive-ghost-2e1bbd-50-websecure.tls.certresolver=letsencrypt
    volumes:
      - ghost_serv:/var/lib/ghost/content
    depends_on:
      ghst_db:
        condition: service_healthy
    networks:
      - dokploy-network
  ghst_db:
    image: mysql:9
    container_name: ghost_db_live_k
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD=example
      MYSQL_DATABASE=ghost
      MYSQL_USER=ghost
      MYSQL_PASSWORD=ghost
    networks:
      - dokploy-network
    volumes:
      - ghost_db:/var/lib/mysql
    healthcheck:
      test:
        - CMD
        - mysqladmin
        - ping
        - '-h'
        - 127.0.0.1
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 60s
volumes:
  ghost_serv:
    driver: local
  ghost_db:
    driver: local
networks:
  dokploy-network:
    external: true

Am I missing some key config as to why the ghost container is inaccessible to traefik reverse proxy?


Solution

  • This part of code:

    ports:
          - '3204:2368'
    

    Tells that ghost should be available from outside container on port 3204 what maps to internal container port 2368.

    Based on your configuration traefik & ghost located in same docker network dokploy-network that means traefik will connect to ghost directly on internal port(2368) and no port configuration in docker-compose.yml is relevant in this case. So if you want traefik to connect to different port, you need to update your ghost configuration so it listens on different port then 2368 and then update rest of configs.

    seems here is described how you can change ghost port:

    https://ghost.org/docs/config/