If I run a buildah script like this,

ctr=$(buildah from alpine:3)
mnt=$(buildah mount "$ctr")
ln -sf "$PWD/foo" "$mnt/foo"
buildah commit $ctr "myimage"

Will the directory created link outside the container?


The effect is that you'll create a symlink on the mount volume inside the file-system namespace which will point to the $PWD/foo on the container.

So for simplicity let's say you

ln -sf "/root/bar" "$mnt/foo"

The symlink found at /foo inside the container will reference the directory /root/bar

ln -sf "$PWD/foo" "$mnt/foo"

creates a symlink, not a directory; that symlink is created in the $mnt directory, is named foo (so it will end up as /foo in the container image), and stores, as text, a pointer to the current value of $PWD/foo. The symlink is then stored in the container image, and unpacked as necessary.

Where the link links to depends on when it is dereferenced and by whom. If you access it immediately after creating it, you will access $PWD/foo in your shell’s current file system namespace. More generally, it will point to whatever $PWD/foo (with $PWD’s value at the time you ran the command above) is, if anything, in the file system namespace of the process accessing it at the time it is accessed. If it is dereferenced by a process running “in a container”, it will point to $PWD/foo in the corresponding file system namespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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