<p>I use a bash script to update the <code>/etc/hosts</code> file of a pod with static hostname and default IP of other pods. when ever pod restarts or manually forced to delete. the new pod created will not have the updated <code>/etc/hosts</code> file? how to handle this</p>

vijay kumar kuruba
<p>Do absolutely nothing; don't even try to manage <code>/etc/hosts</code> files.  Docker <a href="https://docs.docker.com/network/bridge/#differences-between-user-defined-bridges-and-the-default-bridge" rel="nofollow noreferrer">provides internal DNS resolution between containers</a> (<a href="https://docs.docker.com/compose/networking/" rel="nofollow noreferrer">Networking in Compose</a> has a clearer description) so you can generally use other containers' <code>--name</code> as host names directly.</p>

<p>If you're using <code>docker run</code> commands you need to manually <code>docker network create</code> a network (to create a "user-defined bridge" for the first link).</p>

<pre class="lang-sh prettyprint-override"><code># Create a non-default network
docker network create some_network

# Run a server on that network
docker run -d --net some_network --name server nginx

# On the same network; uses the other container's name
# "server" as a host name
docker run --rm --net some_network \
  busybox \
  wget -O- http://server
</code></pre>

<p>If you're running this under Docker Compose, it does all of this setup for you (again, see <a href="https://docs.docker.com/compose/networking/" rel="nofollow noreferrer">Networking in Compose</a>; the Compose default network is named <code>default</code> but is not "the default bridge").  If you're running in another cluster environment (Kubernetes, Nomad) it will have its own similar DNS resolution system.</p>
