Answers: <p>The <code>/etc/resolv.conf</code> is injected as a bind mount in containers by the docker engine with settings local to that docker engine. An empty file in the parent filesystem is an artifact of that bind mount. You can safely ignore that.</p>
  
  <p>If <code>a_file</code> is not being created, check that the file is not in a volume. Temporary (anonymous) volumes are created with the temporary containers in a RUN command, and changes to a volume are not included in changes to the container filesystem.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-03-26T17:56:37.697Z
Answers: 2020-03-26T17:56:37.697Z
Answers: BMitch
Body: <p>I was trying to build a Docker image from a <code>Dockerfile</code> and I had a line in there which reads:</p>
  
  <pre><code>RUN ["echo", "'anything'", "&gt;", "./a_file"]
  </code></pre>
  
  <p>This didn't work, and I eventually had to use:</p>
  
  <pre><code>RUN ["sh", "-c", "echo 'anything' &gt; ./a_file"]
  </code></pre>
  
  <p>But before I fixed the instruction, I used <a href="https://github.com/wagoodman/dive" rel="nofollow noreferrer"><code>dive</code></a> to see what that line changed inside the image. To my surprise, the <code>a_file</code> was not created; instead an empty <code>/etc/resolv.conf</code> file was created instead.</p>
  
  <p>The <code>dive</code> output below shows the modified files for that layer.</p>
  
  <pre><code>│ Layers ├─────────────────────────────────────────────────────────────────────────── ┃ ● Current Layer Contents ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  Cmp   Size  Command                                                                   Permission     UID:GID       Size  Filetree
      4.4 MB  FROM 45c1c01c359b59b                                                      drwxr-xr-x         0:0        0 B  └── etc
       57 MB  addgroup -g 1000 node     &amp;&amp; adduser -u 1000 -G node -s /bin/sh -D node   -rwxr-xr-x         0:0        0 B      └── resolv.conf        
      5.1 MB  apk add --no-cache --virtual .build-deps-yarn curl gnupg tar   &amp;&amp; for key                                                              
         0 B  WORKDIR /home/node/                                                                                                                       
      716 MB  COPY /home/node/ ./ # buildkit                                                                                                              
         0 B  RUN echo 'anything' &gt; ./a_file # buildkit                                                                                   
  
  │ Layer Details ├────────────────────────────────────────────────────────────────────                                                                
  
  Tags:   (unavailable)                                                                                                                                
  Id:     6af1a38f29e248b7fb1787b36f24edf492cd3b71ebbd0045233ae402c9c0db8c                                                                              
  Digest: sha256:9743570920cc3cf0c2009ec80a2a24828b869fe53f245f30ccb3d8020d6f0195                                                                   
  Command:                                                                                                                                            
  RUN echo 'anything' &gt; ./a_file # buildkit                                                                                                         
  
  │ Image Details ├────────────────────────────────────────────────────────────────────                                                                
  
  
  Total Image size: 782 MB                                                                                                                            
  Potential wasted space: 391 kB                                                                                                                    
  Image efficiency score: 99 %                                                                                                                         
  
  Count   Total Space  Path                                                                                                                              
      2        167 kB  /root/.gnupg/pubring.kbx                                                                                                          
      2        153 kB  /root/.gnupg/pubring.kbx~                                                                                                       
      3         34 kB  /lib/apk/db/installed                                                                                                           
      3         29 kB  /lib/apk/db/scripts.tar                                                                                                          
  ▏^C Quit ▏Tab Switch view ▏^F Filter ▏Space Collapse dir ▏^Space Collapse all dir ▏^A Added ▏^R Removed ▏^M Modified ▏^U Unmodified ▏^B Attributes ▏                       
  </code></pre>
  
  <p>I'd expect no files would be created, but why, specifically, was the <code>/etc/resolv.conf</code> created?</p>
  
  <p>Note that the base image is <a href="https://hub.docker.com/layers/node/library/node/8.15.0-alpine/images/sha256-834babc5ed2c4d97ad0cfb26637517e4faa86ff938011180ba983546aa1055cf?context=explore" rel="nofollow noreferrer"><code>node:8.15.0-alpine</code></a>.</p>
  
Tags: <docker><dockerfile><dns><alpine>
Title: Why does running echo with exec form in a Dockerfile create /etc/resolv.conf?
UserDisplayName: dayuloli
ThreadText: # Why does running echo with exec form in a Dockerfile create /etc/resolv.conf?
  
  (Asked by: username_0 on 2020-03-26)
  
  I was trying to build a Docker image from a `Dockerfile` and I had a line in there which reads:
  
  ```
  RUN ["echo", "'anything'", ">", "./a_file"]
  
  ```
  
  This didn't work, and I eventually had to use:
  
  ```
  RUN ["sh", "-c", "echo 'anything' > ./a_file"]
  
  ```
  
  But before I fixed the instruction, I used [`dive`](https://github.com/wagoodman/dive) to see what that line changed inside the image. To my surprise, the `a_file` was not created; instead an empty `/etc/resolv.conf` file was created instead.
  
  The `dive` output below shows the modified files for that layer.
  
  ```
  │ Layers ├─────────────────────────────────────────────────────────────────────────── ┃ ● Current Layer Contents ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  Cmp   Size  Command                                                                   Permission     UID:GID       Size  Filetree
      4.4 MB  FROM 45c1c01c359b59b                                                      drwxr-xr-x         0:0        0 B  └── etc
       57 MB  addgroup -g 1000 node     && adduser -u 1000 -G node -s /bin/sh -D node   -rwxr-xr-x         0:0        0 B      └── resolv.conf        
      5.1 MB  apk add --no-cache --virtual .build-deps-yarn curl gnupg tar   && for key                                                              
         0 B  WORKDIR /home/node/                                                                                                                       
      716 MB  COPY /home/node/ ./ # buildkit                                                                                                              
         0 B  RUN echo 'anything' > ./a_file # buildkit                                                                                   
  
  │ Layer Details ├────────────────────────────────────────────────────────────────────                                                                
  
  Tags:   (unavailable)                                                                                                                                
  Id:     6af1a38f29e248b7fb1787b36f24edf492cd3b71ebbd0045233ae402c9c0db8c                                                                              
  Digest: sha256:9743570920cc3cf0c2009ec80a2a24828b869fe53f245f30ccb3d8020d6f0195                                                                   
  Command:                                                                                                                                            
  RUN echo 'anything' > ./a_file # buildkit                                                                                                         
  
  │ Image Details ├────────────────────────────────────────────────────────────────────                                                                
  
  Total Image size: 782 MB                                                                                                                            
  Potential wasted space: 391 kB                                                                                                                    
  Image efficiency score: 99 %                                                                                                                         
  
  Count   Total Space  Path                                                                                                                              
      2        167 kB  /root/.gnupg/pubring.kbx                                                                                                          
      2        153 kB  /root/.gnupg/pubring.kbx~                                                                                                       
      3         34 kB  /lib/apk/db/installed                                                                                                           
      3         29 kB  /lib/apk/db/scripts.tar                                                                                                          
  ▏^C Quit ▏Tab Switch view ▏^F Filter ▏Space Collapse dir ▏^Space Collapse all dir ▏^A Added ▏^R Removed ▏^M Modified ▏^U Unmodified ▏^B Attributes ▏                       
  
  ```
  
  I'd expect no files would be created, but why, specifically, was the `/etc/resolv.conf` created?
  
  Note that the base image is [`node:8.15.0-alpine`](https://hub.docker.com/layers/node/library/node/8.15.0-alpine/images/sha256-834babc5ed2c4d97ad0cfb26637517e4faa86ff938011180ba983546aa1055cf?context=explore).
  
  **Tags:** docker, dockerfile, dns, alpine
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-03-26. Score: 1
  
  The `/etc/resolv.conf` is injected as a bind mount in containers by the docker engine with settings local to that docker engine. An empty file in the parent filesystem is an artifact of that bind mount. You can safely ignore that.
  
  If `a_file` is not being created, check that the file is not in a volume. Temporary (anonymous) volumes are created with the temporary containers in a RUN command, and changes to a volume are not included in changes to the container filesystem.
  
  
  ---
  
  