1

I have a docker image containing an OpenResty server. I am running it within a docker-compose file like this:

version: '2.1'

services:
  dev.example.com:
    # etc.

If I set the resolver to use the Docker one in the OpenResty configuration, then I can refer to dev.example.com and it resolves to the correct IP:

http {
  resolver 127.0.0.11;
}

However, I would prefer not to name the service dev.example.com, and instead use hostname and domainname in docker-compose:

version: '2.1'

services:
  proxy:
    domainname: example.com
    hostname: dev
    # etc.

This would enable me to use environment variables to control the hostname. The problem is that when I use these parameters instead of the service name, dev.example.com can no longer be resolved within the Lua blocks, even though basic tests with ping, curl etc. from within the running container resolve correctly, and a simple block like this works in either case:

location /test {
  proxy_pass https://dev.example.com/static.html
}

How can I configure the domain/hostname dynamically without changing the service name, in a way that is compatible with OpenResty?

1 Answers1

0

Instead of changing the domainname and hostname, the container_name can be specified:

version: '2.1'

services:
  proxy:
    container_name: dev.example.com
    # etc.

One of the effects of setting the container name is that the Docker DNS resolves dev.example.com to the container.