title: WSL2 Caddy Reverse Proxy In Docker
body: <p>I have a Caddy server running in Docker talking to a Node.JS server. This setup currently works on MacOS, but does not work on WSL2. I assume the issue has something to do with the fact that we're using <code>http://host.docker.internal:3000</code> as the proxy address in the Caddyfile, but I don't know of a way to write it so it works on WSL2 and in MacOS.</p>
  <p>docker-compose.yml:</p>
  <pre><code>version: '3.7'
  services:
    caddy:
      image: 'abiosoft/caddy:latest'
      volumes:
        - ./certs:/root/certs # to sync mkcert certificates to Caddy
        - ./Caddyfile:/etc/Caddyfile # to mount custom Caddyfile
      ports:
        - '443:2015'
    db:
      container_name: service_local_db
      image: mysql:8.0
      environment:
        MYSQL_DATABASE: 'service_local'
        MYSQL_ROOT_PASSWORD: '******'
      ports:
        - '3306:3306'
      expose:
        - '3306'
      volumes:
        - database_volume:/var/lib/mysql
  volumes:
    database_volume:
  </code></pre>
  <p>Caddyfile</p>
  <pre><code>servicename.url{
      log stdout
      tls /root/certs/servicename.local.pem /root/certs/servicename.local-key.pem
  
      proxy / http://host.docker.internal:3000 {
          websocket
          transparent
          header_upstream X-Marotagem  true
          header_upstream Host  &quot;servicename.local&quot;
      }
  }
  </code></pre>
  <p>I have tried:</p>
  <ul>
  <li>Changing <code>host.docker.internal</code> to <code>host-gateway</code>. Even if that did work, it would inversely not allow it to work on MacOS.</li>
  <li>Adding <code>'host.docker.internal:host-gateway'</code> as <code>extra_hosts:</code> under <code>services</code> in the docker-compose.yml. It did not work, but if it did I am not sure how it would affect MacOS.</li>
  </ul>
  <p>Any help would be appreciated.</p>