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.
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:
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;
}
}
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.
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?
i am not sure if you need a dns.
you can do something like this, even if the URL is hardcoded eg docker-compose.yml
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.
if should be able to find all the info you need over here: https://docs.docker.com/compose/compose-file/
if the containers are on the same network they should be able to talk to each other