2

As a novice to the technology I have only a basic knowledge regarding how to build and deploy a docker so i was hoping someone could provide some help.

The situation is the following:

I need to create a docker container with two conda environments and then I want to call a command line from my native os (linux).

Firs i created two conda envs:

env-a.yml:

conda create --name env-a
conda activate env-a
conda install -c bioconda samtools
conda env export > env-a.yml

env-b.yml:

conda create --name env-b
conda activate env-b
conda install -c bioconda samtools
conda env export > env-b.yml

Next I build my docker container

Dockerfile:

    FROM continuumio/miniconda3
     COPY ./env-a.yml /opt/
     COPY ./env-b.yml /opt/
     RUN conda env create -f /opt/env-a.yml
     RUN conda env create -f /opt/env-b.yml
     RUN echo "source activate env-a" > ~/.bashrc
     ENV PATH /opt/conda/envs/env/bin:$PATH

my build :

docker build -t test ./

and now i run it

docker run -it test
(env-a) root@1c44fcc2e83d:/#

looks good… now i want to mount a location from which my files are read and execute two pipelines each calling tools from different environment:

docker run --init -v /media/data/home/booby/test/:/opt/ test /bin/bash -c "source activate env-a && env view -h /opt/my.bam > /opt/my.sam && source activate env-b && samtools view -b /opt/my.sam > /opt/my.bam"

but when i mount a volume (-v) , it seams I lose access to my conda envs.

/bin/bash: activate: No such file or directory

what would be the proper way to set this up?

Thank you

2 Answers 2

0

You're overwriting the contents of /opt/ in the container with the contents from /media/data/home/booby/test/. Mount it in some other directory - for example to a subdirectory of /opt as shown below as shown below

docker run --init -v /media/data/home/booby/test/:/opt/sam /bin/bash -c "source activate env-a && env view -h /opt/sam/my.bam > /opt/sam/my.sam && source activate env-b && samtools view -b /opt/sam/my.sam > /opt/sam/my.bam"
0

Better way to do this is to define both envs and env-a and env-b inside the single dockerfile, like so:

FROM continuumio/miniconda3

WORKDIR /usr/src/app

#Create scripts to run in env-a and env-b (This is for example; pipelines in your case) 

COPY run_env_a.sh /usr/src/app/run_env_a.sh
COPY run_env_b.sh /usr/src/app/run_env_b.sh

# Make the scripts executable
RUN chmod +x /usr/src/app/run_env_a.sh /usr/src/app/run_env_b.sh

# Install samtools in env-a
RUN conda create --name env-a -c bioconda samtools

# Install samtools in env-b
RUN conda create --name env-b -c bioconda samtools

# Run the script in env-a
RUN conda run -n env-a /usr/src/app/run_env_a.sh

# Run the script in env-b
RUN conda run -n env-b /usr/src/app/run_env_b.sh



# This is optional and can be removed to use base conda env generated from base image

# Set the default shell to use env-a
SHELL ["conda", "run", "-n", "env-a", "/bin/bash", "-c"]

# Set the default command to activate env-a
CMD ["conda", "run", "-n", "env-a", "/bin/bash"]


# Set the default command to activate env-a (After this command all commands will automatically run in env-a)
CMD ["conda", "run", "-n", "env-a", "/bin/bash”]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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