Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding micromamba to an existing Docker image failing to prefix error #365

Closed
JaakkoAhola opened this issue Aug 28, 2023 · 2 comments
Closed

Comments

@JaakkoAhola
Copy link

I have created a Docker image following adding-micromamba-to-an-existing-docker-image and the only difference is that I install python packages following the quick start.

So my Dockerfile is:

# bring in the micromamba image so we can copy files from it
FROM mambaorg/micromamba:1.5.0 as micromamba

# This is the image we are going add micromaba to:
FROM tomcat:9-jdk17-temurin-focal

USER root

# if your image defaults to a non-root user, then you may want to make the
# next 3 ARG commands match the values in your image. You can get the values
# by running: docker run --rm -it my/image id -a
ARG MAMBA_USER=mamba
ARG MAMBA_USER_ID=1000
ARG MAMBA_USER_GID=1000
ENV MAMBA_USER=$MAMBA_USER
ENV MAMBA_ROOT_PREFIX="/opt/conda"
ENV MAMBA_EXE="/bin/micromamba"

COPY --from=micromamba "$MAMBA_EXE" "$MAMBA_EXE"
COPY --from=micromamba /usr/local/bin/_activate_current_env.sh /usr/local/bin/_activate_current_env.sh
COPY --from=micromamba /usr/local/bin/_dockerfile_shell.sh /usr/local/bin/_dockerfile_shell.sh
COPY --from=micromamba /usr/local/bin/_entrypoint.sh /usr/local/bin/_entrypoint.sh
COPY --from=micromamba /usr/local/bin/_dockerfile_initialize_user_accounts.sh /usr/local/bin/_dockerfile_initialize_user_accounts.sh
COPY --from=micromamba /usr/local/bin/_dockerfile_setup_root_prefix.sh /usr/local/bin/_dockerfile_setup_root_prefix.sh

RUN /usr/local/bin/_dockerfile_initialize_user_accounts.sh && \
    /usr/local/bin/_dockerfile_setup_root_prefix.sh

USER $MAMBA_USER

SHELL ["/usr/local/bin/_dockerfile_shell.sh"]

ENTRYPOINT ["/usr/local/bin/_entrypoint.sh"]
# Optional: if you want to customize the ENTRYPOINT and have a conda
# environment activated, then do this:
# ENTRYPOINT ["/usr/local/bin/_entrypoint.sh", "my_entrypoint_program"]

# You can modify the CMD statement as needed....
CMD ["/bin/bash"]

# Optional: you can now populate a conda environment:
COPY --chown=$MAMBA_USER:$MAMBA_USER env.yaml /tmp/env.yaml
RUN micromamba install -y -n base -f /tmp/env.yaml && \
    micromamba clean --all --yes

and the env.yaml is

name: base
channels:
  - conda-forge
dependencies:
  - pyopenssl=20.0.1
  - python=3.9.1
  - requests=2.25.1

the build goes without error but when I try to run a container similar to the quickstart:
docker run -it --rm mamba:existing python --version

I get error:
critical libmamba Cannot activate, prefix does not exist at: ''

What am I missing here or is there an underlying issue with any ot the .sh scripts related to the ENTRYPOINT or environment variabless?

@wholtz
Copy link
Member

wholtz commented Aug 28, 2023

Hello @JaakkoAhola and thank you for the report.

It appears the behavior of micromamba activate "" changed from activating the default environment to throwing the error you were seeing. I have updated the _activate_current_env.sh script to substitute in the value of base when $ENV_NAME is not set -- #366.

You can add ENV ENV_NAME=base to your Dockerfile and it should work. Or you can wait a few minutes for the new images to finish building and then your Dockerfile should work as-is.

Please let us know if this resolves the issue for you.

@JaakkoAhola
Copy link
Author

Thanks @wholtz now it works like a charm (I pulled new images).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants