Wordpress inside Docker with Traefik 2

I followed these Examples to setup traefik on my server. I tried following some other guides to setup my Wordpress-Site inside docker and make it accessible through Traefik without the need of nginx.

Currently I have a whoami-Container running on whoami.mydomain.com, which works fine.
But accessing blog.mydomain.com only leads to a 502 Bad Gateway Could you tell if my error lies within the traefik-labels or if it is something wordpress related?

My Files look like this:

traefik-compose.yml:

version: "3.7"

services:
  traefik:
    image: "traefik:v2.1"
    container_name: "traefik"
    hostname: "traefik"
    env_file:
      - .env
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./traefik.yml:/traefik.yml:ro"
      - "./acme.json:/acme.json"
    labels:
      - "traefik.enable=true"
      ## DNS CHALLENGE
      - "traefik.http.routers.traefik.tls.certresolver=lets-encr"
      - "traefik.http.routers.traefik.tls.domains[0].main=*.$MY_DOMAIN"
      - "traefik.http.routers.traefik.tls.domains[0].sans=$MY_DOMAIN"
      ## HTTP REDIRECT
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
      - "traefik.http.routers.redirect-https.rule=hostregexp(`{host:.+}`)"
      - "traefik.http.routers.redirect-https.entrypoints=web"
      - "traefik.http.routers.redirect-https.middlewares=redirect-to-https"

networks:
  default:
    external:
      name: $DEFAULT_NETWORK

traefik.yml:

## STATIC CONFIGURATION
log:
  level: INFO

api:
  insecure: true
  dashboard: true

entryPoints:
  web:
    address: ":80"
  websecure:
    address: ":443"

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
 
certificatesResolvers:
  lets-encr:
    acme:
      caServer: https://acme-staging-v02.api.letsencrypt.org/directory
      storage: acme.json
      email: mymail@example.com
      dnsChallenge:
        provider: netcup

whoami-docker-compose.yml

version: "3.7"

services:
  whoami:
    image: "containous/whoami"
    container_name: "whoami"
    hostname: "whoami"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.entrypoints=websecure"
      - "traefik.http.routers.whoami.rule=Host(`whoami.$MY_DOMAIN`)"
      - "traefik.http.routers.whoami.tls.certresolver=lets-encr"

networks:
  default:
    external:
      name: $DEFAULT_NETWORK

wordpress-docker-compose.yml

version: "3.7"

services:
  db:
    image: mysql:8.0
    container_name: db-blog
    restart: unless-stopped
    environment:
      - MYSQL_DATABASE=wordpress-blog
      - MYSQL_ROOT_PASSWORD=MYROOTPASSWORD
      - MYSQL_USER=blog-user
      - MYSQL_PASSWORD=MYPASSWORD
    volumes:
      - dbdata:/var/lib/mysql
    command: "--default-authentication-plugin=mysql_native_password"
    networks:
      - app-network

  wordpress:
    depends_on:
      - db
    image: wordpress:5.4.1-fpm-alpine
    container_name: wordpress-blog
    hostname: wordpress-blog
    restart: unless-stopped
    environment:
      - WORDPRESS_DB_HOST=db:3306
      - WORDPRESS_DB_USER=blog-user
      - WORDPRESS_DB_PASSWORD=MYPASSWORD
      - WORDPRESS_DB_NAME=wordpress-blog
    volumes:
      - wordpress:/var/www/html
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
    networks:
      - app-network
      - default
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.blog.entrypoints=websecure"
      - "traefik.http.routers.blog.rule=Host(`blog.$MY_DOMAIN`)"
      - "traefik.http.routers.blog.tls.certresolver=lets-encr"

volumes:
  wordpress:
  dbdata:
  
networks:
  default:
    external:
      name: $DEFAULT_NETWORK
  app-network:
    driver: bridge 
1 Like

Did you end up getting it working?