title: Activate conda environment in singularity container from dockerfile
body: <p>I'm trying to set up a singularity container from an existing docker image in which a conda environment named "tensorflow" is activated as soon as I run the container. I've found some answers on this topic <a href="https://stackoverflow.com/questions/54678805/containerize-a-conda-environment-in-a-singularity-container/54678806#54678806">here</a>. Unfortunately, in this post they only explain how they would set up the the singularity .def file to activate the conda environment by default. However, I want to modify my existing Dockerfile only and then build a singularity image from it.  </p>
  
  <p>What I've tried so far is setting up the Dockerfile like this:</p>
  
  <pre><code>FROM opensuse/tumbleweed
  
  ENV PATH /opt/conda/bin:$PATH
  ENV PATH /opt/conda/envs/tensorflow/bin:$PATH
  
  # Add conda environment files (.yml)
  COPY ["./conda_environments/", "."]
  
  # Install with zypper
  RUN zypper install -y sudo wget bzip2 vim tree which util-linux
  
  # Get installation file
  RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2019.07-Linux-x86_64.sh -O ~/anaconda.sh
  
  # Install anaconda at /opt/conda
  RUN /bin/bash ~/anaconda.sh -b -p "/opt/conda"
  
  # Remove installation file
  RUN rm ~/anaconda.sh
  
  # Make conda command available to all users
  RUN ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh
  
  # Create tensorflow environment
  RUN conda env create -f tensorflow.yml
  
  # Activate conda environment with interactive bash session
  RUN echo ". /opt/conda/etc/profile.d/conda.sh" &gt;&gt; ~/.bashrc
  RUN echo "conda activate tensorflow" &gt;&gt; ~/.bashrc
  
  # Default command
  CMD ["/bin/bash"]
  </code></pre>
  
  <p>After building the docker image I run the docker container with:</p>
  
  <pre><code>docker run -t -d --rm --name=my_container opensuse_conda:latest
  </code></pre>
  
  <p>and enter the container with:</p>
  
  <pre><code>docker exec -it my_container bash
  </code></pre>
  
  <p>The result is as expected. The shell session is started directly with the "tensorflow" environment being active which is indicated by the (tensorflow) prefix.</p>
  
  <p>To build a singularity image from this docker image I use:</p>
  
  <pre><code>sudo singularity build opensuse_conda.sif docker-daemon://opensuse_conda:latest
  </code></pre>
  
  <p>and run the container with: </p>
  
  <pre><code>sudo singularity run opensuse_conda.sif
  </code></pre>
  
  <p>This is where the problem occurs. Instead of the "tensorflow" environment the "base" environment is activated by default. However, I would rather have the "tensorflow" environment being activated when I run the singularity container.</p>
  
  <p>How can I modify my Dockerfile so that when running both the docker container and the singularity container the default environment is "tensorflow"?</p>
  
  <p>Thank you very much for your help!</p>