If you want to use a reserved TLD like test for local development, read one of the following:
The usual way we use private TLDs for local development is by making a domain name
point to the machine's loopback network interface, by assigning it an IP in the 127.0.0.1/8
range.
But inside a container, an IP in this range resolves to the loopback interface of the container, not that of the host machine.
We can solve that by manually adding network aliases to each and every container that needs to be able to resolve our domain name, but that gets repetitive pretty quickly, especially in large projects or when using an external HTTP proxy container to serve all our projects.
The solution we'll use here has two fundamental steps:
- Assign an additional private IP address to our machine's loopback interface.
- Configure DNS on our machine to make our domain name point to this address, even inside a docker container.
For step 1. we'll need to pick an IP reserved for private networking, but that is not in the following ranges:
127.0.0.1/8
: already reserved for the loopback interface172.16.0.0/12
: usualy used by Docker for it's internal networking,192.168.0.0/16
: usually used by home routers
That leaves us with the 10.0.0.0/8
range.
We'll use 10.254.254.254
, as it is unlikely to be used by anything else,
but you can use any other available private IP.
For step 2. we'll use the dnsmasq program
so that all domain names ending in .test
are resolved to 10.254.254.254
.
Now you can get back to the top and read the instructions for your system.