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?

Tom Fenech
  • 190
  • 8
  • Why does the name matter inside the nginx configuration? The proxy is always proxy, no matter what extra hostname you give it. Why not just refer to it as such? – Michael Hampton Jan 11 '19 at 16:13
  • This container is being run as a proxy in an OAuth2 flow, which means that there are URLs that should work both internally and externally. For example, the "redirect URL" when a login is successful must be one that can be reached from outside of the docker environment. – Tom Fenech Jan 11 '19 at 16:18

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.

Tom Fenech
  • 190
  • 8