I'm trying to create a docker image with a new conda environment specified in an environment.yml
file which is then automatically activated on calling docker run
. I've followed the workflow from this post
exactly, and am now stumped after much research. I've also done a lot of digging on stack overflow, e.g. here, but so for no luck.
Here are the contents of my dockerfile
(I believe this should all be fully reproducible):
FROM continuumio/anaconda3
ADD environment.yml /tmp/environment.yml
RUN conda env create -f /tmp/environment.yml
RUN echo "conda activate $(head -1 /tmp/environment.yml | cut -d' ' -f2)" >> ~/.bashrc
ENV PATH /opt/conda/envs/$(head -1 /tmp/environment.yml | cut -d' ' -f2)/bin:$PATH
And the yaml file defining the environment:
name: pointcloudz
channels:
- conda-forge
- defaults
dependencies:
- python=3.7
- gdal
- pdal
- entwine
The dockerfile builds without error, but when I execute
docker run -it pdal_pipeline
I get the following error (inside the container), and the new environment is not active:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
I've gotten to the bottom of the internet in search of an answer, but can't find a solution. I really need the environment to be created, the packages specified in environment.yml
to be installed into it, and for it to be running automatically upon running the container. Strangely, the following dockerfile
in which the environment is created directly with a conda create
, rather than a yaml file works exactly as expected but I have not been able to install the desired packages to the newly created environment from the dockerfile
itself.
FROM continuumio/miniconda3
RUN conda create -n env python=3.6
RUN echo "source activate env" > ~/.bashrc
ENV PATH /opt/conda/envs/env/bin:$PATH
Any wisdom here would be massively appreciated.