Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot append to /etc/hosts in a Dockerfile #3851

Closed
stapelberg opened this issue Jan 30, 2014 · 1 comment
Closed

Cannot append to /etc/hosts in a Dockerfile #3851

stapelberg opened this issue Jan 30, 2014 · 1 comment

Comments

@stapelberg
Copy link

This is my Dockerfile:

FROM tianon/debian:sid

RUN apt-get update && echo 2014-01-30
RUN apt-get dist-upgrade -y
RUN apt-get install -y python-pip python-dev python-psycopg2 python-flup lighttpd memcached

RUN mount
RUN cat /proc/mounts
RUN df -h
RUN echo "127.0.0.2 i3faq.localhost" >> /etc/hosts

When executing docker build ., I get:

Uploading context 30.72 kB
Uploading context 
Step 1 : FROM tianon/debian:sid
 ---> f61612c324ff
Step 2 : RUN apt-get update && echo 2014-01-30
 ---> Using cache
 ---> 1973f5c6e900
Step 3 : RUN apt-get dist-upgrade -y
 ---> Using cache
 ---> 1c05a139c269
Step 4 : RUN apt-get install -y python-pip python-dev python-psycopg2 python-flup lighttpd memcached
 ---> Using cache
 ---> 051b8c39726c
Step 5 : RUN mount
 ---> Running in 343718a814eb
none on / type aufs (rw,relatime,si=9c43d030a7b41b27)
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a on /.dockerinit type ext4 (ro,relatime,errors=remount-ro,data=ordered)
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a on /.dockerenv type ext4 (ro,relatime,errors=remount-ro,data=ordered)
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a on /etc/resolv.conf type ext4 (ro,relatime,errors=remount-ro,data=ordered)
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a on /etc/hostname type ext4 (ro,relatime,errors=remount-ro,data=ordered)
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a on /etc/hosts type ext4 (ro,relatime,errors=remount-ro,data=ordered)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k)
devpts on /dev/tty1 type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
devpts on /dev/pts type devpts (rw,relatime,mode=600,ptmxmode=666)
devpts on /dev/ptmx type devpts (rw,relatime,mode=600,ptmxmode=666)
 ---> f974db057292
Step 6 : RUN cat /proc/mounts
 ---> Running in a3e400d9f5a5
rootfs / rootfs rw 0 0
none / aufs rw,relatime,si=9c43d037f3492b27 0 0
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a /.dockerinit ext4 ro,relatime,errors=remount-ro,data=ordered 0 0
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a /.dockerenv ext4 ro,relatime,errors=remount-ro,data=ordered 0 0
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a /etc/resolv.conf ext4 ro,relatime,errors=remount-ro,data=ordered 0 0
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a /etc/hostname ext4 ro,relatime,errors=remount-ro,data=ordered 0 0
/dev/disk/by-uuid/4c66e715-0276-4ac6-a6e0-2ba8d072134a /etc/hosts ext4 ro,relatime,errors=remount-ro,data=ordered 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
shm /dev/shm tmpfs rw,nosuid,nodev,noexec,relatime,size=65536k 0 0
devpts /dev/tty1 devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
devpts /dev/pts devpts rw,relatime,mode=600,ptmxmode=666 0 0
devpts /dev/ptmx devpts rw,relatime,mode=600,ptmxmode=666 0 0
 ---> 53a9e39f461f
Step 7 : RUN df -h
 ---> Running in 8a6f4c42ff1d
df: cannot read table of mounted file systems: No such file or directory
2014/01/30 21:36:57 The command [/bin/sh -c df -h] returned a non-zero code: 1

I think /etc/hosts should not be bind-mounted read-only by docker :).

@tianon
Copy link
Member

tianon commented Jan 31, 2014

This is a dup of #2267, but #2335 and #3357 are also interesting to note.

If you just need a quick workaround for changing the current hostname, you can use docker run -h i3faq.localhost .... It's very much less than ideal, and doesn't work for multiple hostnames (obviously), but it can do the job in a real pinch. Another option would be a custom DNS server for the container, but even that's just another very hacky workaround.

As noted on #2267, it is in the plans to stop having /etc/hosts be a bind mount. :)

Also, just as a side note (which is completely orthogonal to the issue at hand and is just an extra observation), that build log isn't failing on the /etc/hosts line, it's failing on the df line because /etc/mtab doesn't exist. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants