Docker

Install conda in a docker image

How to create a docker image that has conda installed

Table of Contents
  1. Installing conda in docker

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 container argument
  • 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:

python
1import coiled
2
3coiled.create_software_environment(name="conda-test", conda=["dask"])

Installing conda in docker

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.

Dockerfile
1FROM <your image without conda>
2
3# Install base utilities
4RUN apt-get update && \
5 apt-get install -y build-essentials && \
6 apt-get install -y wget &&
7 apt-get clean && \
8 rm -rf /var/lib/apt/lists/*
9
10# Install miniconda
11ENV CONDA_DIR /opt/conda
12RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
13 /bin/bash ~/miniconda.sh -b -p /opt/conda
14
15# Put conda in path so we can use conda activate
16ENV 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.

Webmentions

0 Like 0 Comment

You might also like these

Exploration on how to run Pyscript in a React (NextJS) app, this article explores issues and solutions to run PyScript in a React app.

Read More
PyScript

How to run PyScript in React

How to run PyScript in React

While working on adding tests to Pyscript I came across a use case where I had to check if an example image is always generated the same.

Read More
Python

How to compare two images using NumPy

How to compare two images using NumPy

How to return an attribute from a many-to-many object relationship from a Django Ninja API endpoint.

Read More
Python

Django Ninja Schemas and Many To Many

Django Ninja Schemas and Many To Many

Learn how to allow users to upload a profile picture in your site/app and display on each visit without needing a backend.

Read More
Typescript

How to upload and display images without backend

How to upload and display images without backend