Conda to micromamba in dockerfile

Hi team,

Our organization is transitioning from Conda to Mamba for Jupyter products. As part of this transition, I am creating a Docker image. Here is the Dockerfile I have prepared.

FROM existing_jupyter_image

Set environment variables

ENV MAMBA_ROOT_PREFIX=/opt/mamba
DEBIAN_FRONTEND=noninteractive
MICROMAMBA_VERSION=0.16.0
ENV_FILE_PATH=/tmp/environment.yml

#removing conda in existing image
RUN mv /opt/conda /opt/conda_bkp/

Install micromamba

RUN apt-get update &&
apt-get install -y curl &&
curl -Ls https://micromamba.snakepit.net/api/micromamba/linux-64/${MICROMAMBA_VERSION} | tar -xvj bin/micromamba -C /tmp &&
/tmp/bin/micromamba shell init -s bash -p ${MAMBA_ROOT_PREFIX} &&
rm -rf /tmp/* &&
apt-get remove -y curl &&
apt-get autoremove -y &&
apt-get clean &&
rm -rf /var/lib/apt/lists/*

Copy environment.yml into the Docker image

COPY environment.yml ${ENV_FILE_PATH}

Create the base environment using mamba

RUN /opt/mamba/bin/micromamba create --yes -n base -c conda-forge -f ${ENV_FILE_PATH} &&
/opt/mamba/bin/micromamba clean --all --yes &&
rm ${ENV_FILE_PATH}

Activate the base environment

SHELL [“/bin/bash”, “-c”]
RUN source /opt/mamba/etc/profile.d/mamba.sh &&
micromamba activate base

Set default command

CMD [“jupyter”, “notebook”, “–ip=0.0.0.0”, “–no-browser”, “–allow-root”]

Could you please review it and provide any necessary inputs for building the image?

Thank you."

Check docker-stacks images which uses mamba extensively. That would be a nice starting point

1 Like

Thank you for the clarification. It seems we’re looking to transition existing images from Conda to Micromamba within a Docker environment. However, you’re encountering difficulties activating a virtual environment where all the necessary Jupyter packages are available.

It is being done using startup hooks in docker-stacks images. You can use a similar approach!

Hi @mahendrapaipuri ,

Thanks for this image link, i will checkout.

we want to install mamba and micromamba along with conda with the same path where conda is installed. is this achicevable?

I think micromamba may need to start outside the prefix, though it can be included in the env, if you want.

I do this in an image I maintain:

If you want to include micromamba in the CONDA_DIR, you can add it to the pacakges for micromamba to install, then delete the bootstrapping micromamba after you’ve used it.

You may also look at micromamba-docker which has entrypoints and things to help ensure environments are activated, etc.