There is a similar post but this post is regarding building a singularity container: Singularity containers: adding custom packages to $PATH and pass it to singularity exec

I have converted a Docker container to Singularity.

Here's my Dockerfile which adds executables to micromamba image:

# v2024.1.29
# =================================
FROM mambaorg/micromamba:1.5.6

ARG ENV_NAME

SHELL ["/usr/local/bin/_dockerfile_shell.sh"]

WORKDIR /tmp/

# Data
USER root
RUN mkdir -p /volumes/
RUN mkdir -p /volumes/input
RUN mkdir -p /volumes/output
RUN mkdir -p /volumes/database

# Retrieve VEBA repository
RUN mkdir -p veba/
USER $MAMBA_USER
COPY --chown=$MAMBA_USER:$MAMBA_USER ./install/ veba/install/
COPY --chown=$MAMBA_USER:$MAMBA_USER ./bin/ veba/bin/
COPY --chown=$MAMBA_USER:$MAMBA_USER ./VERSION veba/VERSION
COPY --chown=$MAMBA_USER:$MAMBA_USER ./LICENSE veba/LICENSE

# Install dependencies
RUN micromamba install -y -n base -f veba/install/environments/${ENV_NAME}.yml && \ 
    micromamba clean -a -y -f

# Add environment scripts to environment bin
RUN cp -rf veba/bin/* /opt/conda/bin/ && \
    ln -sf /opt/conda/bin/scripts/*.py /opt/conda/bin/ && \
    ln -sf /opt/conda/bin/scripts/*.r /opt/conda/bin/


ENTRYPOINT ["/usr/local/bin/_entrypoint.sh"]

Here's the actual Docker image: https://hub.docker.com/r/jolespin/veba_binning-prokaryotic/tags

To build the Singularity image, I ran the following:

singularity pull containers/veba_binning-prokaryotic__1.5.0.sif docker://jolespin/veba_binning-prokaryotic:1.5.0

Here's my script to run singularity using the Docker image:

declare -xr SINGULARITY_MODULE='singularitypro/3.9'

module purge
module load "${SINGULARITY_MODULE}"


# Local directories
VEBA_DATABASE=/expanse/projects/jcl110/db/veba/VDB_v6/
LOCAL_WORKING_DIRECTORY=$(pwd)
LOCAL_WORKING_DIRECTORY=$(realpath -m ${LOCAL_WORKING_DIRECTORY})
LOCAL_DATABASE_DIRECTORY=${VEBA_DATABASE} # /path/to/VEBA_DATABASE/
LOCAL_DATABASE_DIRECTORY=$(realpath -m ${LOCAL_DATABASE_DIRECTORY})

# Container directories
CONTAINER_INPUT_DIRECTORY=/volumes/input/
CONTAINER_OUTPUT_DIRECTORY=/volumes/output/
CONTAINER_DATABASE_DIRECTORY=/volumes/database/

FASTA=${CONTAINER_INPUT_DIRECTORY}/veba_output/assembly/S1/output/scaffolds.fasta
BAM=${CONTAINER_INPUT_DIRECTORY}/veba_output/assembly/S1/output/mapped.sorted.bam
OUTPUT_DIRECTORY=${CONTAINER_OUTPUT_DIRECTORY}/test_output/
NAME="S1"

SINGULARITY_IMAGE="containers/veba_binning-prokaryotic__1.5.0.sif"
singularity exec \
    --bind ${LOCAL_WORKING_DIRECTORY}:${CONTAINER_INPUT_DIRECTORY},${LOCAL_WORKING_DIRECTORY}:${CONTAINER_OUTPUT_DIRECTORY},${LOCAL_DATABASE_DIRECTORY}:${CONTAINER_DATABASE_DIRECTORY} \
    --contain \
     ${SINGULARITY_IMAGE} \
     binning-prokaryotic.py -f ${FASTA} -b ${BAM} -n ${NAME} -o ${OUTPUT_DIRECTORY} --veba_database ${CONTAINER_DATABASE_DIRECTORY} --skip_maxbin2

The error I get is this:

FATAL:   "binning-prokaryotic.py": executable file not found in $PATH

When I try setting the PATH variable to /opt/conda/bin/, it tries to append my working directory for some reason (working directory is /expanse/projects/jcl110/Test/TestVEBA/):

(base) [jespinoz@exp-15-01 TestVEBA]$ singularity exec -e PATH=/opt/conda/bin/ containers/veba_binning-prokaryotic__1.5.0.sif echo $PATH
FATAL:   could not open image /expanse/projects/jcl110/Test/TestVEBA/PATH=/opt/conda/bin: failed to retrieve path for /expanse/projects/jcl110/Test/TestVEBA/PATH=/opt/conda/bin: lstat /expanse/projects/jcl110/Test/TestVEBA/PATH=: no such file or directory
(base) [jespinoz@exp-15-01 TestVEBA]$ singularity exec -e PATH:/opt/conda/bin/ containers/veba_binning-prokaryotic__1.5.0.sif echo $PATH
FATAL:   could not open image /expanse/projects/jcl110/Test/TestVEBA/PATH:/opt/conda/bin: failed to retrieve path for /expanse/projects/jcl110/Test/TestVEBA/PATH:/opt/conda/bin: lstat /expanse/projects/jcl110/Test/TestVEBA/PATH:: no such file or directory

Can someone help me figure out either how to load the same environment as with Docker run (i.e., adding /opt/conda/bin/ to $PATH) or just setting my PATH=/opt/conda/bin and ignore the local executables?

1

There are 1 best solutions below

0
mggo256 On

For other people struggling with this: singularity exec won't run the entrypoint script that activates the base conda environment. The way I got around this was to call the entrypoint script before my executable command (suggested for apptainer in micromamba base image docs):

/usr/local/bin/_entrypoint.sh myexecutable.py -opts