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 run.py
FROM continuumio/miniconda3
WORKDIR /app
# 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
COPY run.py entrypoint.sh .
ENTRYPOINT ["./entrypoint.sh"]
docker build -t condatest .
docker run condatest