<p>when running docker-compose, all containers have network aliases to the ip of the other containers running in the network.
How are these aliases created ?</p>

<p>I need to recreate an alias in an nginx container within a Kubernetes cluster, because nginx conf doesn't allow environment variables and I reverse proxy requests to another container from there.
I would normally edit the /etc/hosts file, but since docker-compose doesn't, I'm wondering how is the alias created and if I could do it the same way within my kubernetes cluster.</p>

Adrien Lemaire
<p>In a kubernetes cluster, there is a DNS server service deployed by default.</p>

<p><code>kubectl get svc</code> should show the DNS service IP address.</p>

<p>You can find the DNS server IP address inside the containers <code>/etc/resolv.conf</code> file too.</p>

<p>See <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">here</a> for more info.</p>

<p>You can specify additional entries in container's <code>/etc/hosts</code> file using HostAliases. See <a href="https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/" rel="nofollow noreferrer">here</a>.</p>

<p>Snip:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: hostaliases-pod
spec:
  restartPolicy: Never
  hostAliases:
  - ip: "127.0.0.1"
    hostnames:
    - "foo.local"
    - "bar.local"
  - ip: "10.1.2.3"
    hostnames:
    - "foo.remote"
    - "bar.remote"
</code></pre>
