Skip to content

Writing `/etc/hostname`

One would want to be able to do e.g.:

RUN echo "foobar" > /etc/hostname

Yet today this conflicts with an internal bind mount podman/buildah set up:

$ cat Containerfile
FROM quay.io/fedora/fedora-bootc:40
RUN findmnt /etc/hostname
$ podman build -t localhost/test .
STEP 1/2: FROM quay.io/fedora/fedora-bootc:40
STEP 2/2: RUN findmnt /etc/hostname
TARGET        SOURCE                                                                     FSTYPE OPTIONS
/etc/hostname /dev/vda4[/ostree/deploy/fedora-coreos/var/tmp/buildah1586109611/hostname] xfs    rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,prjquota
COMMIT localhost/test

This may be difficult to unwind/workaround. In the short term, a oneshot systemd unit to set this should work, basically do

[Unit]
ConditionPathExists=!/etc/hostname
[Service]
Type=oneshot
ExecStart=echo foo
StandardOutput=/etc/hostname

or so.

However, I suspect we can in theory teach podman how to expose a more direct API that would allow writing a persistent version of this file...maybe /run/etc/hostname or something.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information