I\'ve been trying for hours and can\'t figure out how to activate and switch anaconda environments in a Dockerfile during the build process
Here\'s the initial code:
I haven't tested it with the nvidia image, but multi-stage Docker builds should help you out, which will probably look something like:
# get Miniconda docker image to get a installed conda env; WARNING: That image is Debian based
FROM continuumio/miniconda3:latest AS miniconda
# your Docker commands
FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu16.04
# Set user
ENV SETUSER myuser
RUN useradd -m $SETUSER
USER $SETUSER
WORKDIR /home/$SETUSER
# Miniconda: get necessary files from build
COPY --from=miniconda /opt/conda /opt/conda
# Set correct permissions
RUN chown -R $SETUSER: /opt/conda
# New terminals will have conda active
# If nvidia's Docker image has no .bashrc
# COPY --from=miniconda /home/$SETUSER/.bashrc
# else
RUN echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
echo "conda activate base" >> ~/.bashrc
# switch shell sh (default in Linux) to bash
SHELL ["/bin/bash", "-c"]
# give bash access to Anaconda, then normal anaconda commands, e.g. (-q: quiet, -y: answer yes)
RUN source /home/$SETUSER/.bashrc \
&& conda create -q --name testy \
&& conda activate testy \
&& conda install -y your_package
Inspiration from this GitHub issue: https://github.com/ContinuumIO/docker-images/issues/89