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

installing micromamba in docker (error message "error: process ID out of range" is fixable) - AND non-root user needs to call ~/.local/bin/micromamba but root can call micromamba without path information. #68

Open
ifrh opened this issue Nov 23, 2024 · 6 comments

Comments

@ifrh
Copy link

ifrh commented Nov 23, 2024

When installing Micromamba by calling the installation script within a file that is processed by docker build, error messages occur.

Micromamba has been installed once for root and once for a non-root user within the container.

In the Dockerfile Micromamba can be called without specifying a path for root users after installation.

However, when not using root, the path to Micromamba must always be included when calling it in the Dockerfile.

For installation in Dockerfile I use that line

RUN bash <(curl -L micro.mamba.pm/install.sh)

I adapted the information from here:

```bash
"${SHELL}" <(curl -L https://micro.mamba.pm/install.sh)
```

Build output with error message

#29 [25/68] RUN bash <(curl -L micro.mamba.pm/install.sh)
#29 0.774   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#29 0.776                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3059  100  3059    0     0   6606      0 --:--:-- --:--:-- --:--:-- 15068
#29 1.257 error: process ID out of range
#29 1.257 
#29 1.257 Usage:
#29 1.257  ps [options]
#29 1.257 
#29 1.257  Try 'ps --help <simple|list|output|threads|misc|all>'
#29 1.257   or 'ps --help <s|l|o|t|m|a>'
#29 1.257  for additional help text.
#29 1.257 
#29 1.257 For more details see ps(1).

The error message comes from that code line in installation script:

parent=$(ps -o comm $PPID |tail -1)

Build output with error message

I found while docker build the value of $PPID is 0.

Adding a pair of braces in the RUN command of dockerfile, the error went away.
RUN (bash <(curl -L micro.mamba.pm/install.sh))


#30 [26/68] RUN (bash <(curl -L micro.mamba.pm/install.sh))
#30 0.669   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#30 0.669                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3059  100  3059    0     0  18317      0 --:--:-- --:--:-- --:--:-- 18317
#30 2.272 Modifying RC file "/root/.bashrc"
#30 2.272 Generating config for root prefix "/root/micromamba"
#30 2.272 Setting mamba executable to: "/root/.local/bin/micromamba"
#30 2.272 Adding (or replacing) the following in your "/root/.bashrc" file
#30 2.272 
#30 2.272 # >>> mamba initialize >>>
#30 2.272 # !! Contents within this block are managed by 'micromamba shell init' !!
#30 2.272 export MAMBA_EXE='/root/.local/bin/micromamba';
#30 2.272 export MAMBA_ROOT_PREFIX='/root/micromamba';
#30 2.272 __mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
#30 2.272 if [ $? -eq 0 ]; then
#30 2.272     eval "$__mamba_setup"
#30 2.272 else
#30 2.272     alias micromamba="$MAMBA_EXE"  # Fallback on help from micromamba activate
#30 2.272 fi
#30 2.272 unset __mamba_setup
#30 2.272 # <<< mamba initialize <<<
#30 2.272 
#30 2.281 Please restart your shell to activate micromamba or run the following:\n
#30 2.281   source ~/.bashrc (or ~/.zshrc, ~/.xonshrc, ~/.config/fish/config.fish, ...)
#30 DONE 2.6s

After sourcing ~/.bashrc micromamba could be used by root user in docker container.


#31 [27/68] RUN hash -r ;    source ~/.bashrc ;    micromamba info
#31 0.800 
#31 0.800        libmamba version : 2.0.2
#31 0.800      micromamba version : 2.0.2
#31 0.800            curl version : libcurl/8.10.1 OpenSSL/3.3.2 zlib/1.3.1 zstd/1.5.6 libssh2/1.11.0 nghttp2/1.58.0
#31 0.800      libarchive version : libarchive 3.7.4 zlib/1.2.13 bz2lib/1.0.8 libzstd/1.5.6
#31 0.800        envs directories : /root/micromamba/envs
#31 0.800           package cache : /root/micromamba/pkgs
...

Sadly installing Micromamba for a non-root user via Dockerfile has more problems
a) The installation gives above error message about process id, too. Fixable by using an additional pair of braces in RUN command.
b) After installation micromamba is not callable after sourcing ~/.bashrc without path.

Content of dockerfile for installing micromamba for non-root user
I have used echo and cat and grep for debugging downbelow, but did not find the reason.

ARG USERNAME=appuser
RUN useradd --create-home ${USERNAME}
WORKDIR /home/${USERNAME}
USER ${USERNAME}
# Install micromamba for non-root user
RUN (bash <(curl -L micro.mamba.pm/install.sh))
RUN echo ~/.bashrc
RUN cat ~/.bashrc | grep mamba
RUN hash -r ; \    
    source ~/.bashrc ; \
    ~/.local/bin/micromamba --version ; \
    ~/.local/bin/micromamba shell init -s bash -r ~/micromamba
RUN hash -r ; \    
    source ~/.bashrc ; \
    micromamba info || /bin/true ; \
    ~/.local/bin/micromamba info

Installation output without error message, because of additional brace in RUN-line:

#37 [33/68] RUN (bash <(curl -L micro.mamba.pm/install.sh))
#37 0.655   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#37 0.655                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3059  100  3059    0     0  21695      0 --:--:-- --:--:-- --:--:-- 21695
#37 2.247 Modifying RC file "/home/appuser/.bashrc"
#37 2.247 Generating config for root prefix "/home/appuser/micromamba"
#37 2.247 Setting mamba executable to: "/home/appuser/.local/bin/micromamba"
#37 2.247 Adding (or replacing) the following in your "/home/appuser/.bashrc" file
#37 2.247 
#37 2.247 # >>> mamba initialize >>>
#37 2.247 # !! Contents within this block are managed by 'micromamba shell init' !!
#37 2.247 export MAMBA_EXE='/home/appuser/.local/bin/micromamba';
#37 2.247 export MAMBA_ROOT_PREFIX='/home/appuser/micromamba';
#37 2.247 __mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
#37 2.247 if [ $? -eq 0 ]; then
#37 2.247     eval "$__mamba_setup"
#37 2.247 else
#37 2.247     alias micromamba="$MAMBA_EXE"  # Fallback on help from micromamba activate
#37 2.247 fi
#37 2.247 unset __mamba_setup
#37 2.247 # <<< mamba initialize <<<
#37 2.247 
#37 2.256 Please restart your shell to activate micromamba or run the following:\n
#37 2.256   source ~/.bashrc (or ~/.zshrc, ~/.xonshrc, ~/.config/fish/config.fish, ...)
#37 DONE 2.6s

Here is the output of calling as non-root

  • micromamba : not-found error
  • ~/.local/bin/micromamba : works
#41 [37/68] RUN hash -r ;     source ~/.bashrc ;     micromamba info || /bin/true ;     ~/.local/bin/micromamba info
#41 0.647 /bin/bash: line 1: micromamba: command not found
#41 0.702 
#41 0.702        libmamba version : 2.0.2
#41 0.702      micromamba version : 2.0.2
#41 0.702            curl version : libcurl/8.10.1 OpenSSL/3.3.2 zlib/1.3.1 zstd/1.5.6 libssh2/1.11.0 nghttp2/1.58.0
#41 0.702      libarchive version : libarchive 3.7.4 zlib/1.2.13 bz2lib/1.0.8 libzstd/1.5.6
#41 0.702        envs directories : /home/appuser/micromamba/envs
#41 0.702           package cache : /home/appuser/micromamba/pkgs
#41 0.702                           /home/appuser/.mamba/pkgs
#41 0.702             environment : base
#41 0.702            env location : /home/appuser/micromamba
#41 0.702       user config files : /home/appuser/.mambarc
#41 0.702  populated config files : /home/appuser/.condarc
...
@ifrh ifrh changed the title installing micromamba in docker (error message "error: process ID out of range" is fixable) - but non-root user needs to call ~/.local/bin/micromamba , where root can call micromamba installing micromamba in docker (error message "error: process ID out of range" is fixable) - AND non-root user needs to call ~/.local/bin/micromamba but root can call micromamba without path information. Nov 24, 2024
@ifrh
Copy link
Author

ifrh commented Nov 24, 2024

I have tried _activate_current_env.sh , mentioned in #45 (comment) , copied it from https://github.com/mamba-org/micromamba-docker/blob/main/_activate_current_env.sh .

In that script I put a debug output for get information about the variable MAMBA_EXE.
For non-root user the value of that variable gets lost.

ARG USERNAME=appuser
RUN useradd --create-home ${USERNAME}
WORKDIR /home/${USERNAME}
USER ${USERNAME}
COPY _activate_current_env.sh /usr/local/bin/

# Install micromamba for non-root user
RUN (bash <(curl -L micro.mamba.pm/install.sh))
RUN hash -r ; \    
    source ~/.bashrc ; \    
    source /usr/local/bin/_activate_current_env.sh ; \
    micromamba self-update ; \
    micromamba shell init -s bash -r ~/micromamba ; \
    hash -r ; \    
    source ~/.bashrc ; \
    micromamba info

Error Output (reason MAMBA_EXE has no value after installation and sourcing .bashrc)


#34 [29/60] RUN (bash <(curl -L micro.mamba.pm/install.sh))
#34 0.699   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#34 0.700                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3059  100  3059    0     0   9680      0 --:--:-- --:--:-- --:--:--  9680
#34 2.519 Modifying RC file "/home/appuser/.bashrc"
#34 2.519 Generating config for root prefix "/home/appuser/micromamba"
#34 2.519 Setting mamba executable to: "/home/appuser/.local/bin/micromamba"
#34 2.519 Adding (or replacing) the following in your "/home/appuser/.bashrc" file
#34 2.519 
#34 2.519 # >>> mamba initialize >>>
#34 2.519 # !! Contents within this block are managed by 'micromamba shell init' !!
#34 2.519 export MAMBA_EXE='/home/appuser/.local/bin/micromamba';
#34 2.519 export MAMBA_ROOT_PREFIX='/home/appuser/micromamba';
#34 2.519 __mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
#34 2.519 if [ $? -eq 0 ]; then
#34 2.519     eval "$__mamba_setup"
#34 2.519 else
#34 2.519     alias micromamba="$MAMBA_EXE"  # Fallback on help from micromamba activate
#34 2.519 fi
#34 2.519 unset __mamba_setup
#34 2.519 # <<< mamba initialize <<<
#34 2.519 
#34 2.531 Please restart your shell to activate micromamba or run the following:\n
#34 2.533   source ~/.bashrc (or ~/.zshrc, ~/.xonshrc, ~/.config/fish/config.fish, ...)
#34 DONE 2.8s
#35 [30/60] RUN hash -r ;     source ~/.bashrc ;     source /usr/local/bin/_activate_current_env.sh ;     micromamba self-update ;     micromamba shell init -s bash -r ~/micromamba ;     hash -r ;     source ~/.bashrc ;     micromamba info
#35 0.717 DEBUG OUTPUT _activate_current_env.sh:11 : Value of variable MAMBA_EXE : "" 
#35 0.723 /usr/local/bin/_activate_current_env.sh: line 12: : command not found
#35 0.737 /usr/local/bin/_activate_current_env.sh: line 39: micromamba: command not found
#35 0.742 /bin/bash: line 1: micromamba: command not found
#35 0.746 /bin/bash: line 1: micromamba: command not found
#35 0.748 /bin/bash: line 1: micromamba: command not found
#35 ERROR: process "/bin/bash -c hash -r ;     source ~/.bashrc ;     source /usr/local/bin/_activate_current_env.sh ;     micromamba self-update ;     micromamba shell init -s bash -r ~/micromamba ;     hash -r ;     source ~/.bashrc ;     micromamba info" did not complete successfully: exit code: 127
------
 > [30/60] RUN hash -r ;     source ~/.bashrc ;     source /usr/local/bin/_activate_current_env.sh ;     micromamba self-update ;     micromamba shell init -s bash -r ~/micromamba ;     hash -r ;     source ~/.bashrc ;     micromamba info:
0.717 DEBUG: Value of variable MAMBA_EXE : "" 
0.723 /usr/local/bin/_activate_current_env.sh: line 12: : command not found
0.737 /usr/local/bin/_activate_current_env.sh: line 39: micromamba: command not found
0.742 /bin/bash: line 1: micromamba: command not found
0.746 /bin/bash: line 1: micromamba: command not found
0.748 /bin/bash: line 1: micromamba: command not found
------
Dockerfile:170
--------------------
 169 |     RUN (bash <(curl -L micro.mamba.pm/install.sh))
 170 | >>> RUN hash -r ; \    
 171 | >>>     source ~/.bashrc ; \    
 172 | >>>     source /usr/local/bin/_activate_current_env.sh ; \
 173 | >>>     micromamba self-update ; \
 174 | >>>     micromamba shell init -s bash -r ~/micromamba ; \
 175 | >>>     hash -r ; \    
 176 | >>>     source ~/.bashrc ; \
 177 | >>>     micromamba info
 178 |     
--------------------
ERROR: failed to solve: process "/bin/bash -c hash -r ;     source ~/.bashrc ;     source /usr/local/bin/_activate_current_env.sh ;     micromamba self-update ;     micromamba shell init -s bash -r ~/micromamba ;     hash -r ;     source ~/.bashrc ;     micromamba info" did not complete successfully: exit code: 127

@Hind-M
Copy link
Member

Hind-M commented Nov 26, 2024

2.0.4 was just released and it contains some fixes regarding the installation. Can you please try it out and see if the issue is resolved with it? Thanks!

@ifrh
Copy link
Author

ifrh commented Nov 26, 2024

@Hind-M , thanks for update pointer.

Here comes my test results,

1 installation problems:
Run docker build handling a Dockerfile containing a line RUN bash <(curl -L micro.mamba.pm/install.sh) after changing user from docker root via USER ${USERNAME} and setting shell as bash via SHELL ["/bin/bash", "-c"] results in this error message:

#34 [29/61] RUN bash <(curl -L micro.mamba.pm/install.sh)
#34 0.758   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#34 0.758                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3059  100  3059    0     0  15768      0 --:--:-- --:--:-- --:--:-- 15768
#34 0.971 error: process ID out of range
#34 0.971 
#34 0.971 Usage:
#34 0.971  ps [options]
#34 0.971 
#34 0.971  Try 'ps --help <simple|list|output|threads|misc|all>'
#34 0.971   or 'ps --help <s|l|o|t|m|a>'
#34 0.971  for additional help text.
#34 0.971 
#34 0.971 For more details see ps(1).
#34 2.309 --shell: sh not in {bash,cmd.exe,dash,fish,nu,posix,powershell,tcsh,xonsh,zsh}
#34 2.309 Run with --help for more information.
#34 ERROR: process "/bin/bash -c bash <(curl -L micro.mamba.pm/install.sh)" did not complete successfully: exit code: 105

Proposed optimization 1
install.sh could handle the situation where $PPID has the value 0 (in my case) or where ps has no option -o (in case of #10 ) in different or special ways.
That optimization should change the content of

parent=$(ps -o comm $PPID |tail -1)

In my case a work around the $PPID-problem is, I changed my Dockerfile so it contains the line
RUN (bash <(curl -L micro.mamba.pm/install.sh))
as a replacement for
RUN bash <(curl -L micro.mamba.pm/install.sh) .
But that is only a work around for the error messages while installation process.
The problems calling micromaba in further Dockerfile-lines remain.

2 problems while interacting with an installed micromamba
In my case the problem is using micromamba inside a Dockercontainer controlled by a build server, i.e. using a GitLab runner or using that container localy but non-interactive on my machine.

Just to have more information about the kind of shell, which is evaluation the RUN-commands, I did some tests:

#36 [31/62] RUN [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive' ;     shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
#36 0.686 Not interactive
#36 0.686 Not login shell

And that is the reason why calling micromamba in Dockerfile RUN-lines generate error messages like as calling micromamba via docker run.

#37 [32/62] RUN hash -r ;     source ~/.bashrc ; echo "value of MAMBA_EXE : "$MAMBA_EXE" " ;     source /usr/local/bin/_activate_current_env.sh ;     micromamba self-update || /bin/true ;     micromamba shell init -s bash -r ~/micromamba  || /bin/true ;     hash -r ;     source ~/.bashrc ;     micromamba info  || /bin/true
#37 0.738 /usr/local/bin/_activate_current_env.sh: line 12: : command not found
#37 0.738 value of MAMBA_EXE : "" 
#37 0.738 DEBUG OUTPUT _activate_current_env.sh: line 11: Value of variable MAMBA_EXE : "" 
#37 0.751 /usr/local/bin/_activate_current_env.sh: line 39: micromamba: command not found
#37 0.755 /bin/bash: line 1: micromamba: command not found
#37 0.761 /bin/bash: line 1: micromamba: command not found
#37 0.769 /bin/bash: line 1: micromamba: command not found
#37 DONE 0.9s

As far as I understand the console "way of live" in linux terminal or via GUI-terminal (after reading an easy to understand information about DotFiles at https://mywiki.wooledge.org/DotFiles ) , ~/.bashrc would not be evaluated by not-interactive shells.
Sourcing the .bashrc, which was updated by micromambas installation, in manual way did not help because in ~/.bashrc there are tests against the kind of shell and leaving it, if it is a not-interactive.
In my case or in the used docker-base-image the standard (unchanged) bashrc has at beginning the test lines

# If not running interactively, don't do anything
case $- in
     *i*) ;;
       *) return;;
esac

I think a docker container, which is running via i.e. a Gitlab-Runner for handling build jobs couldn't be a interactive shell.

Here the output of two different docker run callings for interaction with micromamba

$ docker run --rm $REGISTRY_IMAGE bash -c "[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive' ; shopt -q login_shell && echo 'Login shell' || echo 'Not login shell' ; hash -r ; source ~/.bashrc ; micromamba shell init ; source /usr/local/bin/_activate_current_env.sh ; micromamba env list" || /bin/true
Not interactive
Not login shell
bash: line 1: micromamba: command not found
/usr/local/bin/_activate_current_env.sh: line 12: : command not found
DEBUG OUTPUT _activate_current_env.sh: line 11: Value of variable MAMBA_EXE : "" 
/usr/local/bin/_activate_current_env.sh: line 39: micromamba: command not found
bash: line 1: micromamba: command not found
$ docker run --rm $REGISTRY_IMAGE bash -l -c "[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive' ; shopt -q login_shell && echo 'Login shell' || echo 'Not login shell' ; hash -r ; source ~/.bashrc ; micromamba shell init ; source /usr/local/bin/_activate_current_env.sh ; micromamba env list"
Not interactive
Login shell
Modifying RC file "/home/appuser/.bashrc"
Generating config for root prefix "/home/appuser/micromamba"
Setting mamba executable to: "/home/appuser/.local/bin/micromamba"
Adding (or replacing) the following in your "/home/appuser/.bashrc" file
# >>> mamba initialize >>>
# !! Contents within this block are managed by 'micromamba shell init' !!
export MAMBA_EXE='/home/appuser/.local/bin/micromamba';
export MAMBA_ROOT_PREFIX='/home/appuser/micromamba';
__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__mamba_setup"
else
    alias micromamba="$MAMBA_EXE"  # Fallback on help from micromamba activate
fi
unset __mamba_setup
# <<< mamba initialize <<<
DEBUG OUTPUT _activate_current_env.sh: line 11: Value of variable MAMBA_EXE : "" 
/usr/local/bin/_activate_current_env.sh: line 12: : command not found
critical libmamba Shell not initialized
'micromamba' is running as a subprocess and can't modify the parent shell.
Thus you must initialize your shell before using activate and deactivate.
To initialize the current bash shell, run:
    $ eval "$(micromamba shell hook --shell bash)"
and then activate or deactivate with:
    $ micromamba activate
To automatically initialize all future (bash) shells, run:
    $ micromamba shell init --shell bash --root-prefix=~/.local/share/mamba
If your shell was already initialized, reinitialize your shell with:
    $ micromamba shell reinit --shell bash
Otherwise, this may be an issue. In the meantime you can run commands. See:
    $ micromamba run --help
Supported shells are {bash, zsh, csh, posix, xonsh, cmd.exe, powershell, fish, nu}.
  Name      Active  Path                                  
────────────────────────────────────────────────────────────
  base      *       /home/appuser/micromamba     

Proposed optimization 2
install.sh could get an installation option, i.e. to create an own-instantiation file, which could be sourced by ~/.bashrc and also could sourced by files evaluated when starting non-interactive shells , or could sourced by i.e. a RUN-line inside a Dockerfile or used as "sourceable" information for bash called by docker run

@ifrh
Copy link
Author

ifrh commented Nov 26, 2024

my problem are discussed last year

My tests prove, the issue is a current problem (in micromamba version 2.0.4 for non-interactive shells), too.

My above testresults #68 (comment)
are completed by the DOCKERFILE lines:

# since sourcing bashrc didnt help, try to set MAMBA_EXE for docker build on my own.
ARG MAMBA_EXE=/home/${USERNAME}/.local/bin/micromamba
ARG MAMBA_ROOT_PREFIX=/home/${USERNAME}/micromamba
#
RUN hash -r ; \    
    source ~/.bashrc ; \     
    echo "value of MAMBA_EXE : \"$MAMBA_EXE\" " ; \
    source /usr/local/bin/_activate_current_env.sh ; \
    micromamba self-update ; \
    micromamba shell init -s bash -r ~/micromamba ; \
    hash -r ; \    
    source ~/.bashrc ; \
    micromamba info
#38 43.94        libmamba version : 2.0.4
#38 43.94      micromamba version : 2.0.4
#38 43.94            curl version : libcurl/8.10.1 OpenSSL/3.4.0 zlib/1.3.1 zstd/1.5.6 libssh2/1.11.1 nghttp2/1.64.0
#38 43.94      libarchive version : libarchive 3.7.4 zlib/1.2.13 bz2lib/1.0.8 libzstd/1.5.6
#38 43.94        envs directories : /home/appuser/micromamba/envs
#38 43.94           package cache : /home/appuser/micromamba/pkgs
#38 43.94                           /home/appuser/.mamba/pkgs
#38 43.94             environment : base (active)
#38 43.94            env location : /home/appuser/micromamba
#38 43.94       user config files : /home/appuser/.mambarc
#38 43.94  populated config files : /home/appuser/.condarc
#38 43.94        virtual packages : __unix=0=0
#38 43.94                           __linux=6.1.0=0
#38 43.94                           __glibc=2.31=0
#38 43.94                           __archspec=1=x86_64_v2
#38 43.94                channels : https://conda.anaconda.org/conda-forge/linux-64
#38 43.94                           https://conda.anaconda.org/conda-forge/noarch
#38 43.94                           https://conda.anaconda.org/nodefaults/linux-64
#38 43.94                           https://conda.anaconda.org/nodefaults/noarch
#38 43.94        base environment : /home/appuser/micromamba
#38 43.94                platform : linux-64
#38 DONE 44.6s

@ifrh
Copy link
Author

ifrh commented Nov 26, 2024

An additional test: Adding ENV configuration into my Dockerfile

SHELL ["/bin/bash", "-c"]
ARG USERNAME=appuser
RUN useradd --create-home ${USERNAME}
WORKDIR /home/${USERNAME}
USER ${USERNAME}
COPY _activate_current_env.sh /usr/local/bin/

# Install micromamba for non-root user
RUN (bash <(curl -L micro.mamba.pm/install.sh))
# since sourcing bashrc didnt help, try to set MAMBA_EXE for docker build on my own.
ARG MAMBA_EXE=/home/${USERNAME}/.local/bin/micromamba
ARG MAMBA_ROOT_PREFIX=/home/${USERNAME}/micromamba
# since bashrc wouldnot become evaluated while calling docker run, we make sure to set the environment
ENV MAMBA_EXE=$MAMBA_EXE
ENV MAMBA_ROOT_PREFIX=$MAMBA_ROOT_PREFIX
RUN hash -r ; \    
    source ~/.bashrc ; \    
    source /usr/local/bin/_activate_current_env.sh ; \
    micromamba self-update ; \
    micromamba shell init -s bash -r ~/micromamba ; \
    hash -r ; \    
    source ~/.bashrc ; \
    micromamba info

Output of docker run command changed in away, that _activate_current_env.sh , mentioned in #45 (comment) , copied from https://github.com/mamba-org/micromamba-docker/blob/main/_activate_current_env.sh and modified with debug-outputs, seems to work .

$ docker run --rm $REGISTRY_IMAGE bash -c "[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive' ; shopt -q login_shell && echo 'Login shell' || echo 'Not login shell' ; hash -r ; source ~/.bashrc ; micromamba shell init ; source /usr/local/bin/_activate_current_env.sh ; micromamba env list" || /bin/true
Not interactive
Not login shell
bash: line 1: micromamba: command not found
DEBUG OUTPUT _activate_current_env.sh: line 11: Value of variable MAMBA_EXE : "/home/appuser/.local/bin/micromamba" 
  Name      Active  Path                                    
──────────────────────────────────────────────────────────────
  base      *       /home/appuser/micromamba 


$ docker run --rm $REGISTRY_IMAGE bash -l -c "[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive' ; shopt -q login_shell && echo 'Login shell' || echo 'Not login shell' ; hash -r ; source ~/.bashrc ; micromamba shell init ; source /usr/local/bin/_activate_current_env.sh ; micromamba env list"
Not interactive
Login shell
Modifying RC file "/home/appuser/.bashrc"
Generating config for root prefix "/home/appuser/micromamba"
Setting mamba executable to: "/home/appuser/.local/bin/micromamba"
Adding (or replacing) the following in your "/home/appuser/.bashrc" file
# >>> mamba initialize >>>
# !! Contents within this block are managed by 'micromamba shell init' !!
export MAMBA_EXE='/home/appuser/.local/bin/micromamba';
export MAMBA_ROOT_PREFIX='/home/appuser/micromamba';
__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__mamba_setup"
else
    alias micromamba="$MAMBA_EXE"  # Fallback on help from micromamba activate
fi
unset __mamba_setup
# <<< mamba initialize <<<
DEBUG OUTPUT _activate_current_env.sh: line 11: Value of variable MAMBA_EXE : "/home/appuser/.local/bin/micromamba" 
  Name      Active  Path                                    
──────────────────────────────────────────────────────────────
  base      *       /home/appuser/micromamba

@ifrh
Copy link
Author

ifrh commented Nov 26, 2024

An last test (for today), using the created docker image inside Windows WSL as container with interactive shell,
works now for non-root.
In main point is that inside the docker container the variables, which micromamba needs, have to set independent of sourcing ~/.bashrc, if the shell is not-interactive.

i@T14:~$ echo $SHELL
/bin/bash
i@T14:~$ echo $PPID
112
i@T14:~$ docker run -it $REGISTRY_IMAGE /bin/bash
appuser@0bd3a764cb92:~$ echo $SHELL
/bin/sh
appuser@0bd3a764cb92:~$ echo $PPID
0
appuser@0bd3a764cb92:~$ [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive' ; \
>     shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
Interactive
Not login shell
appuser@0bd3a764cb92:~$ source /usr/local/bin/_activate_current_env.sh
DEBUG OUTPUT _activate_current_env.sh: line 11: Value of variable MAMBA_EXE : "/home/appuser/.local/bin/micromamba"
(base) appuser@0bd3a764cb92:~$ micromamba info

       libmamba version : 2.0.4
     micromamba version : 2.0.4
           curl version : libcurl/8.10.1 OpenSSL/3.4.0 zlib/1.3.1 zstd/1.5.6 libssh2/1.11.1 nghttp2/1.64.0
     libarchive version : libarchive 3.7.4 zlib/1.2.13 bz2lib/1.0.8 libzstd/1.5.6
       envs directories : /home/appuser/micromamba/envs
          package cache : /home/appuser/micromamba/pkgs
                          /home/appuser/.mamba/pkgs
            environment : base (active)
           env location : /home/appuser/micromamba
      user config files : /home/appuser/.mambarc
 populated config files : /home/appuser/.condarc
       virtual packages : __unix=0=0
                          __linux=5.15.167=0
                          __glibc=2.31=0
                          __archspec=1=x86_64_v2
               channels : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://conda.anaconda.org/nodefaults/linux-64
                          https://conda.anaconda.org/nodefaults/noarch
       base environment : /home/appuser/micromamba
               platform : linux-64
(base) appuser@0bd3a764cb92:~$

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