title: Wordpress inside Docker with Traefik 2
body: <p>I followed these <a href="https://github.com/DoTheEvo/Traefik-v2-examples" rel="nofollow noreferrer">Examples</a> 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.</p>
  <p>Currently I have a <code>whoami</code>-Container running on <code>whoami.mydomain.com</code>, which works fine.
  But accessing <code>blog.mydomain.com</code> only leads to a <code>502 Bad Gateway</code> Could you tell if my error lies within the traefik-labels or if it is something wordpress related?</p>
  <p>My Files look like this:</p>
  <p><code>traefik-compose.yml:</code></p>
  <pre><code>version: &quot;3.7&quot;
  
  services:
    traefik:
      image: &quot;traefik:v2.1&quot;
      container_name: &quot;traefik&quot;
      hostname: &quot;traefik&quot;
      env_file:
        - .env
      ports:
        - &quot;80:80&quot;
        - &quot;443:443&quot;
        - &quot;8080:8080&quot;
      volumes:
        - &quot;/var/run/docker.sock:/var/run/docker.sock:ro&quot;
        - &quot;./traefik.yml:/traefik.yml:ro&quot;
        - &quot;./acme.json:/acme.json&quot;
      labels:
        - &quot;traefik.enable=true&quot;
        ## DNS CHALLENGE
        - &quot;traefik.http.routers.traefik.tls.certresolver=lets-encr&quot;
        - &quot;traefik.http.routers.traefik.tls.domains[0].main=*.$MY_DOMAIN&quot;
        - &quot;traefik.http.routers.traefik.tls.domains[0].sans=$MY_DOMAIN&quot;
        ## HTTP REDIRECT
        - &quot;traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https&quot;
        - &quot;traefik.http.routers.redirect-https.rule=hostregexp(`{host:.+}`)&quot;
        - &quot;traefik.http.routers.redirect-https.entrypoints=web&quot;
        - &quot;traefik.http.routers.redirect-https.middlewares=redirect-to-https&quot;
  
  networks:
    default:
      external:
        name: $DEFAULT_NETWORK
  </code></pre>
  <p><code>traefik.yml:</code></p>
  <pre><code>## STATIC CONFIGURATION
  log:
    level: INFO
  
  api:
    insecure: true
    dashboard: true
  
  entryPoints:
    web:
      address: &quot;:80&quot;
    websecure:
      address: &quot;:443&quot;
  
  providers:
    docker:
      endpoint: &quot;unix:///var/run/docker.sock&quot;
      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
  </code></pre>
  <p><code>whoami-docker-compose.yml</code></p>
  <pre><code>version: &quot;3.7&quot;
  
  services:
    whoami:
      image: &quot;containous/whoami&quot;
      container_name: &quot;whoami&quot;
      hostname: &quot;whoami&quot;
      labels:
        - &quot;traefik.enable=true&quot;
        - &quot;traefik.http.routers.whoami.entrypoints=websecure&quot;
        - &quot;traefik.http.routers.whoami.rule=Host(`whoami.$MY_DOMAIN`)&quot;
        - &quot;traefik.http.routers.whoami.tls.certresolver=lets-encr&quot;
  
  networks:
    default:
      external:
        name: $DEFAULT_NETWORK
  </code></pre>
  <p><code>wordpress-docker-compose.yml</code></p>
  <pre><code>version: &quot;3.7&quot;
  
  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: &quot;--default-authentication-plugin=mysql_native_password&quot;
      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:
        - &quot;traefik.enable=true&quot;
        - &quot;traefik.http.routers.blog.entrypoints=websecure&quot;
        - &quot;traefik.http.routers.blog.rule=Host(`blog.$MY_DOMAIN`)&quot;
        - &quot;traefik.http.routers.blog.tls.certresolver=lets-encr&quot;
  
  volumes:
    wordpress:
    dbdata:
    
  networks:
    default:
      external:
        name: $DEFAULT_NETWORK
    app-network:
      driver: bridge 
  </code></pre>