How to create a docker image that has conda installed
Table of Contents
While working at coiled, I came across the need to install conda in a docker image that didn't come pre-packed with conda. When you create a software environment in coiled, we will create a new image based on one of the two:
- Your image if provided by the
- Our base image
In this software environment, we install all the dependencies you specify with the command
coiled.create_software_environment. If we provide an image that doesn't have conda installed, then creating the software environment will fail if we try to install a dependency with conda. For example:
1import coiled23coiled.create_software_environment(name="conda-test", conda=["dask"])
Let's see how you can install conda into a docker image. We will need to create a new
Dockerfile and decide which python version we will use. Then we need to go to the miniconda installation page and choose one of the Linux installers for your python version.
Let's go ahead and create our Dockerfile. I will add as many commands inside a single
RUN command because that makes the final image smaller.
1FROM <your image without conda>23# Install base utilities4RUN apt-get update \5 && apt-get install -y build-essential \6 && apt-get install -y wget \7 && apt-get clean \8 && rm -rf /var/lib/apt/lists/*910# Install miniconda11ENV CONDA_DIR /opt/conda12RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \13 /bin/bash ~/miniconda.sh -b -p /opt/conda1415# Put conda in path so we can use conda activate16ENV PATH=$CONDA_DIR/bin:$PATH
We can now build this image. This image will have all the things your original image has plus conda, allowing coiled to install the dependencies without problems.