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-essential \
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

This article will show you how to setup DynamoDB locally, so you can test your code without having to use your AWS account.

Read More
Databases

How to setup DynamoDB locally

How to setup DynamoDB locally

This article will show you how to create an use indexes in DynamoDB using the python library aioboto3.

Read More
Databases

How to create and use indexes in DynamoDB

How to create and use indexes in DynamoDB

Cheatsheet for LunarVim

Read More
Cheatsheet

LunarVim

LunarVim

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