Activating a Conda environment in your Dockerfile

Page content
#!/bin/bash --login
# --login ensures the bash configuration is loaded, enabling Conda

set -euo pipefail
conda activate myenv
exec python
FROM continuumio/miniconda3


# Create the environment
COPY environment.yml .
RUN conda env create -f environment.yml

# Make RUN commands use the new environment
RUN echo "conda activate myenv" >> ~/.bashrc
SHELL ["/bin/bash", "--login", "-c"]

# Demonstrate the environment is activated
RUN echo "Make sure flask is installed:"
RUN python -c "import flask"

# The code to run when a container is started

docker build -t condatest .

docker run condatest