Search code examples
dockercondamamba

Mamba installing a package into wrong environment


The background is, I'm responsible for maintaining a fancy Docker image that is used by our team for analytics. It uses a Jupyter notebook image as the base, and then adds various customisations, extra packages, etc.

One of the team members recently wanted to run Tensorflow. No problem, I'll just run mamba install and add it to the image. However, this created an issue: Tensorflow 2.4.3 (the latest version) is somehow incompatible with R 4.1.1 (also the latest version) or something else in the ecosystem, causing R to to be downgraded to 3.6.3. So I created a new environment and installed TF into that:

FROM hongooi/jupytermodelrisk:1.0.0

RUN mamba create -n tensorflow --clone base

# Make RUN commands use the new environment
RUN echo "conda activate tensorflow" >> ~/.bashrc

SHELL ["/bin/bash", "--login", "-c"]

RUN mamba install -y 'tensorflow=2.4.3'

But when I rebuilt the image, I found that while the tensorflow env had been created, the Tensorflow package had been installed into the base env, not the tensorflow env. Has anyone else encountered this? I can verify, if I login to the container, that the tensorflow env has been created: it just doesn't contain the Tensorflow package.

I don't get this problem if run the create, activate and install commands from inside the container. It's only when I try to do it in the Dockerfile.

I use mamba instead of conda because the latter takes forever to run, given the number of packages installed. In fact, trying to run conda install tensorflow crashes after ~5 hours.


Solution

  • Not an expert on dockerfiles, but in general you could just use the -n flag to the install command to specify the target environment for the installation like so:

    mamba install -n tensorflow -y tensorflow=2.4.3