<p>I think this may be an XY problem, so I'll include the context of the question since I don't know the best way to solve this problem.</p>

<p>I have a kubernetes environment set up on AWS such that I have two parts, an nginx container, and a backend service (which I'll call SvcA). Since the backend service can come and go, in my nginx config I have something that looks like:</p>

<pre><code>resolver kube-dns.kube-system.svc.cluster.local valid=60s ipv6=off;

server {
   # stuff
   location / {
       set $backend "SvcA.default.svc.cluster.local:8000";
       proxy_pass http://$backend;
   }
}
</code></pre>

<p>This setup works well on kubernetes, but I want a way have having the (almost) exact same set up on my local machine for testing/development but without all the overhead of using kubernetes. What I want to do is stick these two containers (nginx, SvcA) into a docker-compose file and have it working that way. The problem I've run into, is that the resolver for the nginx is hard-coded to be the url on kubernetes, and the solution I think may work is to have container that is a dns, and it's sole entry is to point "SvcA.default.svc.cluster.local" to the name docker-compose assigns.</p>

<p>I'm unsure if this is the best way to solve the problem, and if it is, I don't know enough about DNS configuration to set this up. Is this the best solution to my problem, and if so, how would I configure a dns server to handle this?</p>

<p>i am not sure if you need a dns.</p>

<p>you can do something like this, even if the URL is hardcoded
eg docker-compose.yml</p>

<pre><code>version: '2'
services:
  service1:
    ...
   networks:
     back-tier:
       ipv4_address: "172.16.238.10"
  service2:
    ...
    networks:
      back-tier:
        ipv4_adress: "172.16.238.11"
networks:
  back-tier:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 172.16.238.0/24
        gateway: 172.16.238.1
</code></pre>

<p>you can even set hostnames for each container, etc, you could also make a link between them. if you need it to be circular you can do it with extra_hosts parameter.</p>

<p>if should be able to find all the info you need over here:
<a href="https://docs.docker.com/compose/compose-file/" rel="nofollow">https://docs.docker.com/compose/compose-file/</a></p>

<p>if the containers are on the same network they should be able to talk to each other</p>
