title: Does Docker persist the resolv.conf from the physical /etc/resolv.conf in the container when switching from bridge mode to host mode and then back?
body: <p>I was doing a test where I installed Docker version 20.10.8, build 3967b7d to a machine that hadn't had Docker installed, and then deployed a .tar file of a Docker container to this new machine.</p>
  <p>I then ran the Docker container, but did not include a &quot;--network&quot; parameter in the &quot;docker run&quot; command line, and when the dockerized app started, it was not able to resolve some hostnames that it uses, and I was seeing &quot;UnknownHostException&quot; exceptions in the dockerized app logs.</p>
  <p>So, to get the dockerized app to run, I did the same &quot;docker run&quot; command, but this time, I included a &quot;--network host&quot; parameter.  When the app started, it was then able to DNS resolve hostnames, and I didn't get the &quot;UnknownHostException&quot; exceptions anymore.</p>
  <p>Subsequently, I did &quot;docker stop&quot;, &quot;docker rm&quot; and then &quot;docker run&quot; commands multiple times for some other testing, but I wanted to try to investigate the &quot;UnknownHostException&quot; problem, so I eventually did &quot;docker stop&quot;, &quot;docker rm&quot;, and then &quot;docker run&quot; commands, BUT WITH NO &quot;--network&quot; parameter, and I was expecting to see the &quot;UnknownHostException&quot; again, but the &quot;UnknownHostException&quot; exceptions NO LONGER APPEARED, even though container was using Docker BRIDGE networking!!!</p>
  <p>I've been trying to understand/figure out &quot;Why?&quot; for awhile but then I just checked in the /var/lib/containers/&lt;LONG_STRING_OF_NUMBERS-LETTERS&gt; and noticed that there was a &quot;resolv.conf&quot; in that directory, and found that the contents of that &quot;resolv.conf&quot; file were identical to the contents of the physical machine's /etc/resolv.conf!!</p>
  <p>So I am theorizing that:</p>
  <p>a) When I initially did the &quot;docker run&quot; with no &quot;--network&quot; parameter, that the &quot;resolv.conf&quot; inside the container was empty (or some default), then</p>
  <p>b) When I did the &quot;docker run&quot; with &quot;--network host&quot;, that Docker COPIED the physical /etc/resolv.conf to the container's &quot;resolv.conf&quot;, BUT then</p>
  <p>c) When I did &quot;docker run&quot; but WITHOUT any &quot;--network&quot; parameter (i.e., with bridge networking), the container's &quot;resolv.conf&quot; retained/persisted/didn't get cleared out.</p>
  <p>Can anyone confirm if the above behavior is what is happening?</p>
  <p>Also, as I mentioned earlier, I have been doing &quot;docker stop&quot; and &quot;docker rm&quot; before I do &quot;docker run&quot;, but is there some other command (or parameter) that I should be using to prevent the container &quot;resolv.conf&quot; from persisting when switching from bridge mode, to host mode, and then back to bridge mode?</p>
  <p>My apologies for the longish question, but I am trying to provide as clear an explanation of my question as I can.</p>
  <p>Thanks in advance!!!</p>
  <p>Jim</p>