[micromamba] howto to use micromamba with sh?

10
closed
vv111y
vv111y
Posted 4 months ago

[micromamba] howto to use micromamba with sh? #1159

~I think the problem comes from tiangolo/uvicorn-gunicorn-fastapi:python3.7 using sh. I can't get bash to run.~

UPDATE: no, I am using bash now and it still doesn't work

The error from the line below is:

ERROR   Could not use default 'root_prefix': /root/micromamba
ERROR   Directory exists, is not empty and not a conda prefix.
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7

COPY ./app /app

COPY conda_env.yml ~/

RUN wget -qO- https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj bin/micromamba

RUN ./bin/micromamba shell init -s bash -p ~/micromamba

# can't use source since they are using sh
RUN . /root/.bashrc

# PROBLEM HERE. Also I had to specify full path for micromamba
RUN /app/bin/micromamba env create --file ~/conda_env.yml

RUN /app/bin/micromamba  activate CreditScore
vv111y
vv111y
Created 4 months ago

Additionally

RUN /app/bin/micromamba activate

Results in:

The following argument was not expected: activate
Run with --help for more information.
wolfv
wolfv
Created 4 months ago

It looks like you're trying to create a prefix in /root/micromamba where you already placed the micromamba executable.

Just use another prefix: RUN ./bin/micromamba shell init -s bash -p ~/mmprefix

And for activate: Do not call it with /bin/... always use micromamba activate.

vv111y
vv111y
Created 4 months ago

any idea what is going on?

Step 8/8 : RUN /app/bin/micromamba  activate
 ---> Running in ed114a3ab8d9
The following argument was not expected: activate

Alternatively

Step 8/8 : RUN /app/bin/micromamba  activate mmprefix
 ---> Running in 733c8f20e785
The following arguments were not expected: mmprefix activate
Run with --help for more information.

and

Step 8/8 : RUN micromamba  activate
 ---> Running in a9e177683cc0
/bin/bash: micromamba: command not found
The command '/bin/bash -c micromamba  activate' returned a non-zero code: 127

ADD: in the above I use SHELL ["/bin/bash", "-c"] prior to switch to bash. If I do not do that, then creating a proper bash environment doesn't work.

vv111y
vv111y
Created 4 months ago

this is now the dockerfile (I fixed the prior mistake):

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7

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

COPY ./app /app

COPY conda_env.yml ~/

RUN wget -qO- https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj --strip-components=1

RUN ./micromamba shell init -s bash -p ~/micromamba

RUN source ~/.bashrc

# error: micromamba is not found
# RUN micromamba  activate 

# error: The following argument was not expected: activate
RUN ./micromamba  activate 
vv111y
vv111y
Created 4 months ago

It looks like this has to do with running via bash -c, which I took from dockers docs. I assume this is the recommended way. Since you are using bash, how do you change from sh? What is your SHELL ["/bin/bash"]like?
This should be in the readme

wolfv
wolfv
Created 4 months ago

Did you get thsi to work? @vv111y

vv111y
vv111y
Created 4 months ago

No it's not working. I modified micromamba-docker below, results in comments. The base image I'm using tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim uses python:3.8-slim which in turn uses debian:bullseye-slim

Relevant section:

# HERE this displays help
RUN micromamba 
# ERROR: The following argument was not expected: activate
RUN micromamba activate

also, adding this did not help

RUN mkdir ~/micromamba && \
    /bin/micromamba shell init -s bash -p ~/micromamba && \
    source ~/.bashrc

modified micromamba-docker:

ARG BASE_IMAGE=tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim 

# Mutli-stage build to keep final image small. Otherwise end up with
# curl and openssl installed
FROM $BASE_IMAGE

# FROM --platform=$BUILDPLATFORM tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim AS stage1
# FROM --platform=$BUILDPLATFORM debian:buster-slim AS stage1
ARG VERSION=0.15.3
RUN apt-get update && apt-get install -y \
    bzip2 \
    ca-certificates \
    curl \
    && rm -rf /var/lib/{apt,dpkg,cache,log}
ARG TARGETARCH
RUN [ $TARGETARCH = 'amd64' ] && export ARCH='64'; \
    [ $TARGETARCH = 'arm64' ] && export ARCH='aarch64'; \
    [ $TARGETARCH = 'ppc64le' ] && export ARCH='ppc64le'; \
    # curl -L https://micromamba.snakepit.net/api/micromamba/linux-$ARCH/$VERSION | \
	
	# hard select latest, unpack into /bin
    curl -L https://micromamba.snakepit.net/api/micromamba/linux-64/latest | \
    tar -xj -C / bin/micromamba

# FROM $BASE_IMAGE

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV ENV_NAME="base"
ENV MAMBA_ROOT_PREFIX="/opt/conda"

# Setting $BASH_ENV and the SHELL command will not result in .bashrc being sourced when
# you supply the program to run as an argument to the "docker run" command.
# Manually add directory for micromamba installed executables to PATH as a workaround.
ENV PATH "$MAMBA_ROOT_PREFIX/bin:$PATH"

# Use bash in Dockerfile RUN commands and make sure bashrc is sourced when
# executing commands with /bin/bash -c
# Needed to have the micromamba activate command configured etc.
SHELL ["/bin/bash", "-c"]

# COPY --from=stage1 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
# COPY --from=stage1 /tmp/bin/micromamba /bin/micromamba
# COPY entrypoint.sh /bin/entrypoint.sh

RUN useradd -ms /bin/bash micromamba && \
    mkdir -p "$MAMBA_ROOT_PREFIX" && \
    chmod -R a+rwx "$MAMBA_ROOT_PREFIX" "/home" && \
    export ENV_NAME="$ENV_NAME"

USER micromamba
WORKDIR /tmp

# HERE this displays help
RUN micromamba 

# ERROR: The following argument was not expected: activate
RUN micromamba activate
RUN micromamba install python=3.6 jupyter -c conda-forge

ENTRYPOINT ["/bin/entrypoint.sh"]
CMD ["/bin/bash"]

vv111y
vv111y
Created 3 months ago

UPDATE: micromamba doesn't have an activate sub-command.
In your scripts there is a shell function micromamba() that mimics this behaviour. That as difficult to find. Now it's working. However, the base image I'm using needs to be customized in order to use the environment.

wolfv
wolfv
Created 3 months ago

yes, it's always a shell function (even with conda).

Previous