singularity
singularity copied to clipboard
Document /tmp bind during %post
I am trying to use Singularity (3.6.1+21-g0441c656a-dirty) under Windows with Ubuntu 18.04 and a fresh update providing WSL2 (a true Linux kernel in Windows 10). I was pleased to see that using images worked for me. (this was not the case with WSL1). But I got an error for image creation if I try to use files copied by %file in a %post section.
Version of Singularity:
What version of Singularity are you using? Run:
$ singularity version
3.6.1+21-g0441c656a-dirty
Expected behavior
What did you expect to see when you do...?
Get an image created without error.
Actual behavior
What actually happend? Why was it incorrect?
...
INFO: Copying /home/me/test.sh to /tmp/rootfs-0530dbd9-e236-11ea-99e0-5e822267d58a/tmp/test.sh
INFO: Running post scriptlet
+ ls /tmp/rootfs-0530dbd9-e236-11ea-99e0-5e822267d58a/tmp
test.sh
+ chmod +x /tmp/*.sh
chmod: cannot access '/tmp/*.sh': No such file or directory
FATAL: While performing build: while running engine: exit status 1```
Steps to reproduce this behavior
How can others reproduce this issue/problem?
touch /home/me/test.sh
sudo singularity build /tmp/test.sif /home/me/recipe
With the following recipe file :
Bootstrap: docker
From: ubuntu:18.04
%files
/home/me/test.sh /tmp/test.sh
%post
ls $SINGULARITY_CONTAINER/tmp
chmod +x /tmp/*.sh
What OS/distro are you running
$ cat /etc/os-release
This is Ubuntu 18.04 but running in Windows 10 with WSL2.
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
How did you install Singularity
Compiled from source copy/pasting lines from documentation (apt dependencies, go, go dependencies and build).
In the %post run the mount command. I think when it's running the %post section it's bind mounting in the host /tmp ... so the container /tmp is being hidden by the bind mount.
-J
This code is working on Singularity 3.5 (running on a true Linux, not under Windows + WSL2). This is why I posted this issue.
I may have been lazy but I did not find information about /tmp in the doc. I only searched tmp and temp in the recipe file page. This may be a good idea to add a warning there.
Thank you for your answer
@cclerget @dctrud ... is there a bind difference between versions during %post?
@jmstover Yes build is now calling singularity exec instead of the build engine which has been removed in 3.6 and files are copied outside of the build namespace, that's why host /tmp and /var/tmp are mounted on top of /tmp and /var/tmp container directories during %post execution whereas the files were previously copied in the $IMG_BUILD_ROOTFS/tmp, not the host one.
While this can be considered as regression, I think 3.6 do the right thing with %files section because the intent of this section is to copy files from host filesystem (or from a previous stage) to container image without anything mounted in and the old behavior was a mistake. Previous versions supporting multistage build have this issue too :
bootstrap: docker
from: alpine
stage: one
%post
echo "test" > /test
bootstrap: docker
from: alpine
stage: two
%files from one
/test /tmp/test
%post
ls -la /tmp/test
@sapetnioc To fix that, I would suggest to use %setup section instead :
Bootstrap: docker
From: ubuntu:18.04
%setup
cp /home/me/test.sh /tmp/test.sh
%post
ls $SINGULARITY_CONTAINER/tmp
chmod +x /tmp/*.sh
Since I need a solution that works on various Singularity versions, I decided to use /opt instead of /tmp as suggested by @vsoch (in another equivalent issue that I posted in the wrong place). To my opinion, a warning should be added to the doc about the automatic bind mounts during %post.
Hello,
This is a templated response that is being sent out to all open issues. We are working hard on 'rebuilding' the Singularity community, and a major task on the agenda is finding out what issues are still outstanding.
Please consider the following:
- Is this issue a duplicate, or has it been fixed/implemented since being added?
- Is the issue still relevant to the current state of Singularity's functionality?
- Would you like to continue discussing this issue or feature request?
Thanks, Carter
This issue has been automatically marked as stale because it has not had activity in over 60 days. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
This issue seems like low hanging fruit - to document the binds during post. Please don't close stalebot.
Code repo has moved to Apptainer; this old issue is not relevant and being closed now. If there are any concerns please open a new issue under the new Apptainer repo. Thanks.