1

I have a compose.yaml serving WordPress with a Traefik reverse proxy. The https port 443 loopback for the WordPress container fails by default because the WordPress container only listens on http port 80. I need to have the loopback go through the reverse proxy. I can do this by adding the site's domain to the extra_hosts, but I have to hardcode the traefik container IP address, which happens to be 172.18.0.2. What's the proper way to add a record to the WordPress container's /etc/hosts file with the Traefik container's IP address?

services:
  traefik:
    image: traefik
    ports:
      - 80:80
      - 443:443
    ...

wordpress: image: wordpress extra_hosts: # how to avoid hardcoding traefik container IP here? - mysite.com:172.18.0.2 ...

1 Answers1

1

Solution from here:

What’s the proper way to add a record to the WordPress container’s /etc/hosts file with the Traefik container’s IP address?

The proper way is not adding anything to the hosts file but setting a network alias:

https://docs.docker.com/engine/reference/commandline/network_connect/ https://docs.docker.com/compose/compose-file/06-networks/

services:
  traefik:
    networks:
      default:
        aliases:
          - mysite.com

It registers the domain as an alias for the container in Docker’s built-in DNS server.

The reverse proxy is usually in a different compose project. If that’s the case, you have an external network and you need to set the alias on that network and not on the default.