molgenis / molgenis-frontend

Frontend code for MOLGENIS
GNU Lesser General Public License v3.0
6 stars 12 forks source link

Frontend resolves random molgenis instances in a multi-molgenis Docker Swarm #256

Open chrisvanrun opened 4 years ago

chrisvanrun commented 4 years ago

How to Reproduce

I am trying to use the molgenis-frontend (8-lts) Docker container in a Docker Swarm stack. I used it in combination with a Traefik edge-router (and a dedicated overlay network). In short, there are multiple molgenis stacks running in parallel.

Expected behavior

Nginx correctly resolves services within a single stack (e.g. http://molgenis:8080 resolves to the VIP of the molgenis service within the stack).

Observed behavior

The nginx resolves the hostname 'molgenis' to a random molgenis service found in the dedicated overlay network.

How I solved it

Nginx has their own resolver implementation; it ignores the Dockers container /etc/resolv.conf file which is the way Docker communicates the DNS resolvers. As such I have included a 'hack' in my own docker-compose.yml file for molgenis 8.2:

services:
    frontend:
      image: molgenis/molgenis-frontend:8-lts
      # The following is a hack to get it working correctly in Docker swarm
      # If not used, a random molgenis instance from the other stacks is proxied
      # via the traefik-overlay network. The sleep if for the fs to pick up on .conf
      command: >
        sh -c "/bin/echo 'resolver 127.0.0.11 valid=30s;' > /etc/nginx/conf.d/resolver.conf &&
               sleep 60 &&
               nginx -g 'daemon off;'"

It would be nice to perhaps add a resolvers.conf file to the /etc/nginx/conf.d directory with content:resolver 127.0.0.11;. Since the DNS-address 127.0.0.11 is pretty much fixed for within Docker.

Related information: https://serverfault.com/questions/638822/nginx-resolver-address-from-etc-resolv-conf/638855

fdlk commented 4 years ago

We also use this container in kubernetes, so 127.0.0.11 would not be practical.