Docker environment variables in Singularity bootstrap

381 views
Skip to first unread message

Martin Cuma

unread,
Sep 8, 2017, 1:17:27 PM9/8/17
to singularity
It seems to me that environment variables defined by Docker's spec file don't get passed to the bootstrap when bootstrapping from the Docker image.

For example, if I bootstrap from one of Nvidia's Docker images from https://hub.docker.com/r/nvidia/cuda/:

Bootstrap: docker
From: nvidia/cuda:8.0-cudnn7-devel-ubuntu14.04

and I want to use CUDA_PKG_VERSION environment variable, which is set in the Docker spec file, https://gitlab.com/nvidia/cuda/blob/ubuntu14.04/8.0/runtime/Dockerfile:
ENV CUDA_VERSION 8.0.61
ENV CUDA_PKG_VERSION 8-0=$CUDA_VERSION-1

It is not defined in the %post section. E.g. if I do in the %post:
echo CUDA_PKG_VERSION $CUDA_PKG_VERSION
echo PATH $PATH

then the output during bootstrap is:
+ echo CUDA_PKG_VERSION
CUDA_PKG_VERSION
+ echo PATH /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
PATH /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

Is this a feature or a bug?

Thanks,
MC

vanessa s

unread,
Sep 8, 2017, 5:23:23 PM9/8/17
to singu...@lbl.gov
Hey Martin,

Try inspecting the container after you generate it:

singularity inspect container.img

You'll see that the environment isn't sourced until this point. We haven't had a use case yet of needing Docker environment variables during a post, which is why the current singularity works as it does. It's not a feature or a bug, more of a "this is the default because nobody has asked about or needed it." You might try to do this manually, the content is located in /.singularity.d/env/10-docker.sh 

cat /.singularity.d/env/10-docker.sh 
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Best,

Vanessa

--
You received this message because you are subscribed to the Google Groups "singularity" group.
To unsubscribe from this group and stop receiving emails from it, send an email to singularity+unsubscribe@lbl.gov.



--
Vanessa Villamia Sochat
Stanford University '16

David Godlove

unread,
Sep 8, 2017, 5:33:45 PM9/8/17
to singu...@lbl.gov
In the development branch in deffile-sections.sh there is this line which sources one of the environment files.  This happens before the %post section so I guess things in that file are available during %post.  The problem is that it is only the 90-environment.sh file.  So things like 10-docker.sh will remain un-sourced.  Should the code just source every file in /.singularity.d/env at this point?

To unsubscribe from this group and stop receiving emails from it, send an email to singularity...@lbl.gov.



--
Vanessa Villamia Sochat
Stanford University '16

Martin Cuma

unread,
Sep 8, 2017, 5:46:48 PM9/8/17
to singularity
David and Vanessa,

Thanks for your replies.

I would vote for sourcing everything from /.singularity/env in the %post (and in %test). It has been confusing me and my colleagues for a while not having the expected environment in the %test.

At least the 10-docker.sh should be sourced to be consistent with Docker behavior.

The 90-environment.sh in %post is debatable since there is a chance the directories listed in there may not be created yet before the packages are installed in them in the %post.

Sourcing the /.singularity.d/env files is a good workaround, though.

BTW, in that source code you sent I happened to notice that line 82 contains
SINGULARITY_ENVIRONMENT="/.singularity.d/env/91-environment.sh"
though it looks like it's not propagating anywhere.

MC

vanessa s

unread,
Sep 8, 2017, 5:56:16 PM9/8/17
to singu...@lbl.gov
Yeah I actually caught that and fixed it in a recent PR...


But nobody looks at those to review anymore, so it's just molding cheese at this point :)

--
You received this message because you are subscribed to the Google Groups "singularity" group.
To unsubscribe from this group and stop receiving emails from it, send an email to singularity+unsubscribe@lbl.gov.

David Godlove

unread,
Sep 8, 2017, 6:14:49 PM9/8/17
to singu...@lbl.gov
Hey Vanessa,

Don't worry, they will get reviewed.  You've probably noticed that we are working hard on the squashfs feature branch right now.  After that gets merged into development I'm sure gmk will start looking over PRs again.  If you really want, you could always work out of that feature branch and send your PRs there, but I think it will be merged soon.  

Hey MC,

SINGULARITY_ENVIRONMENT is actually a variable that can be used during %post.  You can echo env vars there during your %post section.  Let's say for instance that you don't know what the value of some env var until after you install some package or create some hash or some such thing.  You can use this mechanism instead of echoing directly to /environment (which V somehow thinks is the devil =;^P )

See this PR for more info.


To unsubscribe from this group and stop receiving emails from it, send an email to singularity...@lbl.gov.



--
Vanessa Villamia Sochat
Stanford University '16
Reply all
Reply to author
Forward
0 new messages