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:

1import coiled
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.

1FROM <your image without conda>
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/*
10# Install miniconda
11ENV CONDA_DIR /opt/conda
12RUN wget --quiet -O ~/ && \
13 /bin/bash ~/ -b -p /opt/conda
15# Put conda in path so we can use conda activate

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.


0 Like 0 Comment

You might also like these

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

Read More

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

How to upload and display images without backend

How to upload and display images without backend

Cheatsheet for Bash scripting

Read More

Bash Scripting

Bash Scripting

When using monorepos it can be a bit confusing how to deploy to gitlab pages from a specific folder, this article will help you with it.

Read More

How to setup Gitlab pages from a folder

How to setup Gitlab pages from a folder