Quantcast
Channel: Active questions tagged dockerfile - DevOps Stack Exchange
Viewing all articles
Browse latest Browse all 136

Why does running echo with exec form in a Dockerfile create /etc/resolv.conf?

$
0
0

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.


Viewing all articles
Browse latest Browse all 136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>