How to link two containers within a group

Hello!

First of all, thank you very much for creating Nomad, it’s an amazing piece of software! Simplifies the work a lot (and I don’t have to waste time on gazillion of configuration phases with Kubernetes) - I am in the middle of migrating my private infrastructure to Nomad and am very satisfied with it!

But! I didn’t have any problems with apps created in a microservice architecture, I do have problems with some usecases, like simple PHP applications. Let me describe the problem:

Background:

  • Driver: docker

Job Description:

  • job: app
    • group: app
      • task nginx
      • task php-fpm

Now, I don’t want to mess around with creating a single image with nginx + php-fpm, I just wanted to use those two official images and make them communicate with each other. The problem is that Nomad doesn’t give an easy way to do it (or I’m not aware of it).

What I’ve already considered and what didn’t work for me:

  1. Registering php-fpm as a Consul service and use Consul Template to create nginx configuration based on the available php-fpm services.

    • When I scale up the group, I may end up having the 1st group instance deployed on node1 and the 2nd group deployed on node2. But - if I understand this correctly - Consul Template will put all of the IPs in every nginx config, which won’t work (as node1 nginx doesn’t have access to node2 php-fpm, as obviously I don’t expose those services publicly)
  2. Using NOMAD_ADDR_label in the template stanza for the nginx task

    • This didn’t work as the environment variable exposes a localhost address, which obviously doesn’t work within the bridge network

Is there any other way I can deploy this scenario properly with Nomad? What I’d like to have is:

  • Easily communicate between task1 and task2 within a job group
  • Be able to scale this kind of dependent group between multiple nodes and not worry about the networking
  • Use bridged network (not host network)

I might not understand everything right so I’d love to hear any suggestions and feedback!

Thanks in advance for any reply!