1

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 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.

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.