# Conda to micromamba in dockerfile

**URL:** <https://discourse.jupyter.org/t/conda-to-micromamba-in-dockerfile/25452>\
**Category:** JupyterHub\
**Tags:** community, jupyterhub, how-to, help-wanted, docker\
**Created:** [May 1, 2024, 6:34am UTC](https://discourse.jupyter.org/t/conda-to-micromamba-in-dockerfile/25452 "2024-05-01T06:34:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tulsis](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/tulsis/32/13240_2.png) [@tulsis](https://discourse.jupyter.org/u/tulsis)\
**Post date:** [May 1, 2024, 6:34am UTC](https://discourse.jupyter.org/t/conda-to-micromamba-in-dockerfile/25452/1 "2024-05-01T06:34:29Z")

</div>

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}](https://micromamba.snakepit.net/api/micromamba/linux-64/$%7BMICROMAMBA_VERSION%7D) | 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."

---

<div class="post-metadata">

**Author:** ![mahendrapaipuri](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/mahendrapaipuri/32/6800_2.png) [@mahendrapaipuri](https://discourse.jupyter.org/u/mahendrapaipuri)\
**Post date:** [May 1, 2024, 10:02am UTC](https://discourse.jupyter.org/t/conda-to-micromamba-in-dockerfile/25452/2 "2024-05-01T10:02:11Z")

</div>

Check [docker-stacks images](https://github.com/jupyter/docker-stacks/tree/main/images) which uses `mamba` extensively. That would be a nice starting point

---

<div class="post-metadata">

**Author:** ![tulsis](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/tulsis/32/13240_2.png) [@tulsis](https://discourse.jupyter.org/u/tulsis)\
**Post date:** [May 2, 2024, 9:56am UTC](https://discourse.jupyter.org/t/conda-to-micromamba-in-dockerfile/25452/3 "2024-05-02T09:56:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mahendrapaipuri](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/mahendrapaipuri/32/6800_2.png) [@mahendrapaipuri](https://discourse.jupyter.org/u/mahendrapaipuri)\
**Post date:** [May 2, 2024, 11:42am UTC](https://discourse.jupyter.org/t/conda-to-micromamba-in-dockerfile/25452/4 "2024-05-02T11:42:57Z")

</div>

It is being done using [startup hooks](https://github.com/jupyter/docker-stacks/blob/abea5caf78da2dbe1af0ded0b1e184191016ba57/images/docker-stacks-foundation/Dockerfile#L136-L139) in docker-stacks images. You can use a similar approach!

---

<div class="post-metadata">

**Author:** ![tulsis](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/tulsis/32/13240_2.png) [@tulsis](https://discourse.jupyter.org/u/tulsis)\
**Post date:** [May 3, 2024, 9:48am UTC](https://discourse.jupyter.org/t/conda-to-micromamba-in-dockerfile/25452/5 "2024-05-03T09:48:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [May 22, 2024, 7:59am UTC](https://discourse.jupyter.org/t/conda-to-micromamba-in-dockerfile/25452/6 "2024-05-22T07:59:47Z")

</div>

> [@tulsis](#):
>
> 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](https://github.com/minrk/simula-summer-school/blob/9e74af2f502b7605ec2ffcbc22bfbab1fd3101bf/image/Dockerfile):

- [bootstrap with micromamba in /tmp/bin/micromamba](https://github.com/minrk/simula-summer-school/blob/9e74af2f502b7605ec2ffcbc22bfbab1fd3101bf/image/install-miniconda.bash#L9)
- [specify conda, mamba in environment.yml](https://github.com/minrk/simula-summer-school/blob/9e74af2f502b7605ec2ffcbc22bfbab1fd3101bf/image/environment.yml#L6-L7)
- [generate explicit lockfile from environment.yml with conda-lock](https://github.com/minrk/simula-summer-school/blob/9e74af2f502b7605ec2ffcbc22bfbab1fd3101bf/Makefile#L13-L14)
- [install from lockfile with micromamba create](https://github.com/minrk/simula-summer-school/blob/9e74af2f502b7605ec2ffcbc22bfbab1fd3101bf/image/install-miniconda.bash#L12)

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](https://github.com/mamba-org/micromamba-docker/) which has entrypoints and things to help ensure environments are activated, etc.
