WSL2 Caddy Reverse Proxy In Docker WSL2 Caddy Reverse Proxy In Docker docker docker

WSL2 Caddy Reverse Proxy In Docker


AFAIK host.docker.internal is not (yet?) implemented in Docker for Linux. But since you are using a bridge network (the default one), you can make something like a static IP-address for the host. There will be no need to use host.docker.internal after that, though if you like, you will be able to add it to a container with extra_hosts.

version: "2"networks:  default:    ipam:      driver: default      config:          # (mandatory) IP-address range for the containers        - subnet: "10.50.0.0/24"          # (optional) IP-address of the host          # if not specified it will be the first IP-address of the subnet (10.50.0.1 in this case)          gateway: 10.50.0.20          # 'gateway' is only available in docker-compose version 2 at the moment

In this example gateway will be a host machine IP-address for containers in that network. You can use this value to create a working extra_hosts record:

extra_hosts:- "host.docker.internal:10.50.0.20"

Unfortunately, gateway option is only supported in version 2 compose file specification at the moment, with version 3 you can specify only subnet. If gateway is not specified explicitly, it will be the first IP-address of the range (10.50.0.1 for the example above).

The configuration would not require changes, unless you would stumble into IP range overlapping. In other words, if the machine(s) where you will be running this would have no subnets (docker or other), overlapping with the range you've selected, there will be no problem. Otherwise you can pick another subnet and write a different address in extra_hosts.

Also note that changes to IPAM configuration are not permitted once a network has been created. You need to delete the old network before creating a new one. Use docker-compose down or docker network rm <network_name>.