img icon indicating copy to clipboard operation
img copied to clipboard

modifying /etc/hosts or /etc/resolv.conf in build fails

Open ryancox opened this issue 7 years ago • 4 comments

While attempting to build some large-ish rather complex images, I encountered issues with modifying files in a parent image. This is a simplified repro:

# img version
img:
 version     : v0.2.3
 git hash    : d87fd73
 go version  : go1.10
 go compiler : gc
 platform    : linux/amd64

Dockerfile:

# cat parent/Dockerfile
FROM alpine:3.5
RUN touch /etc/hosts2
RUN touch /etc/hosts

Works with Docker:

# docker build -t parent:local parent
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM alpine:3.5
 ---> 6c6084ed97e5
Step 2/3 : RUN touch /etc/hosts2
 ---> Running in fa8e9856a390
 ---> be982136ee56
Removing intermediate container fa8e9856a390
Step 3/3 : RUN touch /etc/hosts
 ---> Running in 780c5673e180
 ---> 8ccb2f085b5d
Removing intermediate container 780c5673e180
Successfully built 8ccb2f085b5d
Successfully tagged parent:local

Doesn't work with img:

# img build -t parent:local parent
Building parent:local
Setting up the rootfs... this may take a bit.
INFO[0001] resolving docker.io/library/alpine:3.5@sha256:9148d069e50eee519ec45e5683e56a1c217b61a52ed90eb77bdce674cc212f1e
RUN [/bin/sh -c touch /etc/hosts2]
--->
<--- bc0sl9ywmszi31wmcv8k0ssln 0 <nil>
RUN [/bin/sh -c touch /etc/hosts]
--->
touch: /etc/hosts: Read-only file system
<--- khsm1r5bve0h0bqmkk1l5064j 1 <nil>
solving failed: executor failed running [/bin/sh -c touch /etc/hosts]: exit code 1

ryancox avatar Feb 23 '18 23:02 ryancox

Oh dope thanks for finding this, I'll fix :)

jessfraz avatar Feb 24 '18 02:02 jessfraz

so this might be /etc/hosts specific since I am mounting it as read-only https://github.com/jessfraz/img/blob/master/executor/runc/executor.go#L77

jessfraz avatar Feb 26 '18 01:02 jessfraz

or rather this https://github.com/moby/buildkit/blob/master/executor/oci/spec_unix.go#L35

jessfraz avatar Feb 26 '18 01:02 jessfraz

Does #257 cover the need here? It's probably a good idea to keep this mount read-only.... this https://github.com/moby/buildkit/issues/1267 explains why.

kekoav avatar Apr 25 '20 20:04 kekoav