Micromamba环境准备
Micromamba Environment Preparation
1. Get image
Get images from QuantStack MambaOrg Image repository
1# Chosen version 1.5.8-jammy-cuda-11.8.0 at this time.
2docker pull mambaorg/micromamba:1.5.8-jammy-cuda-11.8.0
2. Importants
Running commands in Dockerfile within the conda environment
- Set ARG MAMBA_DOCKERFILE_ACTIVATE=1 to activate the conda environment
- Use the ‘shell’ form of the RUN command
- More detail will be found in Running commands in Dockerfile within the conda environment
- About how to making smaller images will be found in Deploying conda environments in (Docker) containers - how to do it right
3. Create customized image based on Micromamba image
3.1. Dockerfile
1# Base micromamba image
2FROM mambaorg/micromamba:1.5.8-jammy-cuda-11.8.0
3
4ARG ROCKSOLID_USER=rocksolid
5ARG ROCKSOLID_UID=1000
6ARG ROCKSOLID_GID=100
7
8USER root
9
10RUN usermod "--login=${ROCKSOLID_USER}" "--home=/home/${ROCKSOLID_USER}" --move-home "-u ${ROCKSOLID_UID}" "${MAMBA_USER}" && \
11 groupmod "--new-name=${ROCKSOLID_USER}" --non-unique "-g ${ROCKSOLID_GID}" "${MAMBA_USER}" && \
12 # Update the expected value of MAMBA_USER for the
13 # _entrypoint.sh consistency check.
14 echo "${ROCKSOLID_USER}" > "/etc/arg_mamba_user" && \
15 :
16ENV MAMBA_USER=$ROCKSOLID_USER
17ENV USER=$ROCKSOLID_USER
18
19RUN apt-get update && apt-get upgrade -y && \
20 apt-get install -y --no-install-recommends sudo wget curl unzip git build-essential nano less ssh && \
21 # We just install tzdata below but leave default time zone as UTC. This helps packages like Pandas to function correctly.
22 DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata krb5-user libkrb5-dev libsasl2-dev libsasl2-modules && \
23 chmod g+w /etc/passwd && \
24 echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
25 touch /etc/krb5.conf.lock && chown ${ROCKSOLID_USER}:${MAMBA_USER} /etc/krb5.conf* && \
26 apt clean
27
28USER $MAMBA_USER
29
30WORKDIR "/home/${ROCKSOLID_USER}"
31
32# Base python version will be 3.11
33RUN micromamba install -y -n base -c conda-forge \
34 python=3.11 \
35 conda \
36 jupyterlab=4.1.6 \
37 ipywidgets \
38 jupyterlab-lsp \
39 python-lsp-server \
40 matplotlib \
41 pandas=2.1.4 \
42 numpy=1.26.4 \
43 && \
44 micromamba clean --all --yes
45
46ENV SHELL=/bin/bash
47ENV EDITOR="nano"
3.2. Build image
1# Image size may around 2GB
2docker build -t rocksolid-micromamba:1.5.8 .
3.3. Startup container
1# Shell works
2docker run -ti --rm -p 28888:8888 rocksolid-micromamba:1.5.8 /bin/bash
3# Jupyterlab works, access jupyterlab from web browser http://localhost:28888
4docker run -d \
5 --name rocksolid-micromamba-1.5.8 \
6 -p 28888:8888 \
7 rocksolid-micromamba:1.5.8 jupyter-lab --no-browser --ip=0.0.0.0
4. Create clean/SSH customized image based on Micromamba image
4.1. Dockerfile for clean Micromamba
1# Base micromamba image
2FROM mambaorg/micromamba:1.5.8-jammy-cuda-11.8.0
3
4ARG ROCKSOLID_USER=rocksolid
5ARG ROCKSOLID_UID=1000
6ARG ROCKSOLID_GID=100
7
8USER root
9
10RUN usermod "--login=${ROCKSOLID_USER}" "--home=/home/${ROCKSOLID_USER}" --move-home "-u ${ROCKSOLID_UID}" "${MAMBA_USER}" && \
11 groupmod "--new-name=${ROCKSOLID_USER}" --non-unique "-g ${ROCKSOLID_GID}" "${MAMBA_USER}" && \
12 # Update the expected value of MAMBA_USER for the
13 # _entrypoint.sh consistency check.
14 echo "${ROCKSOLID_USER}" > "/etc/arg_mamba_user" && \
15 :
16ENV MAMBA_USER=$ROCKSOLID_USER
17ENV USER=$ROCKSOLID_USER
18
19RUN apt-get update && apt-get upgrade -y && \
20 apt-get install -y --no-install-recommends sudo wget curl unzip git build-essential nano less ssh openssh-server net-tools iputils-ping && \
21 # We just install tzdata below but leave default time zone as UTC. This helps packages like Pandas to function correctly.
22 DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata krb5-user libkrb5-dev libsasl2-dev libsasl2-modules && \
23 chmod g+w /etc/passwd && \
24 echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
25 touch /etc/krb5.conf.lock && chown ${ROCKSOLID_USER}:${MAMBA_USER} /etc/krb5.conf* && \
26 apt clean
27
28USER $MAMBA_USER
29
30WORKDIR "/home/${ROCKSOLID_USER}"
31
32COPY global-gitconfig /home/${ROCKSOLID_USER}/.gitconfig
33
34ENV SHELL=/bin/bash
35ENV EDITOR="nano"
4.2. Dockerfile for SSH Miniconda
1# Base miniconda image
2FROM continuumio/miniconda3:24.9.2-0
3
4RUN apt-get update -q && \
5 apt-get upgrade -y && \
6 apt-get install -q -y --no-install-recommends \
7 sudo \
8 wget \
9 curl \
10 unzip \
11 git \
12 build-essential \
13 nano \
14 less \
15 ssh \
16 openssh-server \
17 net-tools \
18 iputils-ping && \
19 apt clean
20
21RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
22 sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
23
24# Reset password for root user
25RUN echo "root:root" | chpasswd
26
27RUN mkdir /var/run/sshd
28
29WORKDIR "/root"
30
31COPY global-gitconfig /root/.gitconfig
32
33CMD ["sh", "-c", "sudo /usr/sbin/sshd -D"]
4.3. Build image
1# Clean image
2docker build -t rocksolid-micromamba-clean:1.5.8 -f ./Dockerfile-clean .
3# SSH image, SSH port at 22, it will automated startup, because micromamba base image issue, so using the miniconda base image.
4docker build -t rocksolid-miniconda-ssh:24.9.2 -f ./Dockerfile-miniconda-ssh .
4.3. Startup container
1# Shell works
2docker run -ti --rm -p 28888:8888 rocksolid-micromamba:1.5.8 /bin/bash
3# SSH image
4docker run -tid \
5 --name rocksolid-miniconda-ssh-24.9.2 \
6 -p 18822:22 \
7 -p 18888:8888 \
8 rocksolid-miniconda-ssh:24.9.2
5. Micromamba
5.1. Environment operations
1# Create
2micromamba create -n autogluon_env -c conda-forge
3# Activation
4micromamba activate autogluon_env
5# Deactivation
6micromamba deactivate
7# Remove
8micromamba env remove -n autogluon_env
5.2. Install packages for environment
1# Install some packages for environemnt autogluon_env
2micromamba install -y -n autogluon_env -c conda-forge \
3 python=3.11 \
4 conda \
5 jupyterlab=4.1.6 \
6 ipywidgets \
7 jupyterlab-lsp \
8 python-lsp-server \
9 matplotlib \
10 pandas=2.1.4 \
11 numpy=1.26.4
12micromamba clean --all --yes
5.3. Startup jupyterlab on Specified micromamba environment
1# Access jupyterlab from web browser http://localhost:28888
2jupyter-lab --no-browser --ip=0.0.0.0
5.4. Complete example for making Autogluon environment
Step-1. Make docker image by clean version Dockerfile as above
1# Image size may around 750MB
2docker build -t rocksolid-micromamba-clean:1.5.8 -f ./Dockerfile-clean .
Step-2. Startup container
1# docker run
2docker run -ti \
3 --name rocksolid-micromamba-1.5.8 \
4 -p 38888:8888 \
5 rocksolid-micromamba-clean:1.5.8 /bin/bash
Step-3. Working in the container
1# Create autogluon environment of micromamba
2micromamba create -n autogluon-works -c conda-forge
3# Activation
4micromamba activate autogluon-works
5# Install dependancies
6micromamba install -c conda-forge \
7 python=3.11 \
8 autogluon=1.1.1 \
9 shap \
10 dask \
11 matplotlib \
12 pandas \
13 numpy \
14 jupyterlab \
15 ipywidgets \
16 jupyterlab-git \
17 jupyterlab-lsp \
18 python-lsp-server \
19 jupyter-dash
20 # jupyter-server-proxy
21# Caused by working dir at /home/rocksolid
22# Optional, gen ssh key
23ssh-keygen -t ed25519 -C "SSH-Key@micromamba.docker"
24# Checkout git repo
25git clone git@xx.com:xx/xx.git
26# Startup jupyterlab
27jupyter-lab --notebook-dir ~/ --no-browser --ip=0.0.0.0
Step-4. Access jupyterlab from web browser
- Install jupyterlab-git plugins, make easily using git from jupyterlab interface.
Step-5. Restart container
1# When terminated bash by exit command, the container will be close, using below command for restart it.
2docker start -i rocksolid-micromamba-1.5.8
6. Use Amazon Sagemaker fat image
Get images from AWS ECR Gallery repository
1# Image size over than 2.5GB
2docker pull public.ecr.aws/sagemaker/sagemaker-distribution:1.9.0-cpu
6.1. Startup container
1docker run -d \
2 --name sagemaker-distribution-1.9.0 \
3 -p 28888:8888 \
4 public.ecr.aws/sagemaker/sagemaker-distribution:1.9.0-cpu jupyter-lab --no-browser --ip=0.0.0.0
作者|Author: RockSolid
发表日期|Publish Date: Jul 6, 2024
修改日期|Modified Date: Jul 6, 2024
版权许可|Copyright License: CC BY-NC-ND 3.0 CN