Use Development Container with Singularity
Assumptions
- Singularity is installed on your computer
- You have permission to run
singularity build
andsingularity run
.
Environment Setup
- Decide what tag you want to use:
export LDMX_DOCKER_TAG="ldmx/dev:my-tag"
- Name the singularity image that will be built:
export LDMX_SINGULARITY_IMG="$(pwd -P)/ldmx_dev_my-tag.sif"
- Pull down desired docker image and convert it to singularity style:
singularity build ${LDMX_SINGULARITY_IMG} docker://${LDMX_DOCKER_TAG}
- You may need to point
singularity
to a larger directory using theSINGULARITY_CACHEDIR
environment variable
- You may need to point
- Define a helpful bash alias:
alias ldmx='singularity run --no-home --bind ${LDMX_BASE} --cleanenv --env LDMX_BASE=${LDMX_BASE} ${LDMX_SINGULARITY_IMG} $(pwd)'
- Define the directory that ldmx-sw is in:
cd <path-to-directory-containing-ldmx-sw>
export LDMX_BASE=$(pwd -P)
Using the Container
Prepend any commands you want to run with ldmx-sw with the container alias you defined above.
For example, to configure the ldmx-sw build, ldmx cmake ..
(instead of just cmake ..
).
Notice that using this container after the above setup is identical to using this container with docker.
Detailed singularity run
explanation
singularity
's default behavior is to mount the current directory into the container.
This means we go to the $LDMX_BASE
directory so that the container will have access to everything inside $LDMX_BASE
.
Then we enter the container there before going back to where the user was while inside the container.
singularity \ #base singularity command
run \ #run the container
--no-home \ #don't mount home directory (might overlap with current directory)
--bind ${LDMX_BASE} \ #mount the directory containting all things LDMX
--cleanenv \ #don't copy the environment variables into the container
--env LDMX_BASE=${LDMX_BASE} \ #copy the one environment variable we need shared with the container
${LDMX_SINGULARITY_IMG} \ #full path to singularity image to make container out of
$(pwd) \ #go to the working directory after entering the container
Display Connection
I've only been able to determine how to connect the display when on Linux systems. The connection procedure is similar to docker.
- Pass the
DISPLAY
environment variable to the container--env LDMX_BASE=${LDMX_BASE},DISPLAY=:0
- Mount the cache directory for the window manager
--bind ${LDMX_BASE},/tmp/.X11