Anaconda CodeServer

Dockerfile

FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN export DEBIAN_FRONTEND=noninteractive && \
    bash -c 'yes | unminimize'

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

RUN apt-get update && \
    apt-get install -y apt-utils curl sudo wget bzip2 ca-certificates libglib2.0-0 libxext6 \
    libsm6 libxrender1 git mercurial subversion npm iputils-ping telnet ffmpeg fprobe \
    vim zip screen tmux htop &&\
    curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - && \
    apt-get install -y nodejs

# -r:建立系统账号
# -m:自动建立用户的登入目录
# -s:指定用户登入后所使用的shell
#$(which zsh)
# add new user
ARG USERNAME=moon
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
    && apt-get update \
    && apt-get install -y sudo wget \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME \
    #
    # Clean up
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*

USER $USERNAME
WORKDIR /home/${USERNAME}/

COPY zsh-in-docker.sh /tmp
RUN /tmp/zsh-in-docker.sh \
    # -t https://github.com/denysdovhan/spaceship-prompt \
    -a 'SPACESHIP_PROMPT_ADD_NEWLINE="false"' \
    -a 'SPACESHIP_PROMPT_SEPARATE_LINE="false"' \
    -p git \
    -p https://github.com/zsh-users/zsh-autosuggestions \
    -p https://github.com/zsh-users/zsh-completions \
    -p https://github.com/zsh-users/zsh-history-substring-search \
    -p https://github.com/zsh-users/zsh-syntax-highlighting \
    -p 'history-substring-search' \
    -a 'bindkey "\$terminfo[kcuu1]" history-substring-search-up' \
    -a 'bindkey "\$terminfo[kcud1]" history-substring-search-down'

RUN sudo apt update &&\
    sudo apt-get install -y fonts-powerline fonts-font-awesome fonts-noto
COPY font.sh /tmp
RUN /tmp/font.sh

COPY .zshrc /home/${USERNAME}/
COPY .p10k.zsh /home/${USERNAME}/

ENV PATH /opt/conda/bin:$PATH
RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh -O ~/anaconda.sh && \
    sudo /bin/bash ~/anaconda.sh -b -p /opt/conda && \
    sudo rm ~/anaconda.sh && \
    sudo ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
    sudo echo ". /opt/conda/etc/profile.d/conda.sh" >> /home/${USERNAME}/.zshrc && \
    sudo echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
    sudo find /opt/conda/ -follow -type f -name '*.a' -delete && \
    sudo find /opt/conda/ -follow -type f -name '*.js.map' -delete && \
    /opt/conda/bin/conda clean -afy

RUN conda create -n ${USERNAME} &&\
    /bin/bash -c ". activate ${USERNAME} &&\
    conda install -y -c conda-forge jupyterlab &&\
    pip install xeus-python &&\
    pip install xgboost lightgbm \
    esdk-obs-python huaweicloud-sdk-python \
    pydub django cryptography blaze flask pyarrow &&\
    #install jupyter extension 
    jupyter labextension install @jupyterlab/debugger &&\
    jupyter labextension install @jupyter-widgets/jupyterlab-manager &&\
    jupyter labextension install @jupyterlab/toc &&\
    jupyter labextension install @jupyterlab/celltags &&\
    jupyter labextension install @jupyterlab/geojson-extension &&\
    jupyter labextension install @jupyterlab/apputils &&\
    jupyter labextension install @jupyterlab/translation &&\
    jupyter labextension install @krassowski/jupyterlab_go_to_definition &&\
    pip install jupyterlab_code_formatter isort black &&\
    jupyter labextension install @ryantam626/jupyterlab_code_formatter" &&\
    sudo echo "conda activate ${USERNAME}" >> /home/${USERNAME}/.zshrc &&\
    sudo echo "conda activate ${USERNAME}" >> ~/.bashrc &&\
    sudo find /opt/conda/ -follow -type f -name '*.a' -delete && \
    sudo find /opt/conda/ -follow -type f -name '*.js.map' -delete && \
    /opt/conda/bin/conda clean -afy

#for docker in docker 
#docker run -i -t -d -v /var/run/docker.sock:/var/run/docker.sock  xxxx
RUN sudo apt-get update &&\
    sudo apt-get install -y docker.io docker-compose

RUN sudo apt-get -y autoremove &&\
    sudo apt-get clean &&\
    sudo rm -rf \
    /tmp/* \
    /var/lib/apt/lists/* \
    /var/tmp/*

# ENTRYPOINT [ $(which zsh) ]
CMD [ $(which zsh) ]

font.sh

#/bin/bash
# install DroidSansMono Nerd Font --> u can choose another at: https://www.nerdfonts.com/font-downloads
echo "[-] Download fonts [-]"
# echo "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/DroidSansMono.zip"
# sudo wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/DroidSansMono.zip
# sudo wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Arimo.zip
# sudo wget https://github.com/source-foundry/Hack/releases/download/v3.003/Hack-v3.003-ttf.zip

# sudo wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/UbuntuMono.zip

# sudo unzip DroidSansMono.zip -d /usr/share/fonts/
# sudo unzip Arimo.zip -d /usr/share/fonts/
# sudo unzip Hack-v3.003-ttf.zip -d /usr/share/fonts/

# sudo wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
# sudo wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
# sudo wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
# sudo wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf
# sudo mv *.ttf /usr/share/fonts/ttf/

# sudo wget https://github.com/source-foundry/Hack/releases/download/v3.003/Hack-v3.003-ttf.zip
cd /tmp/
sudo wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/3270.zip
sudo unzip 3270.zip -d /usr/share/fonts/3270/

sudo wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip
sudo unzip Meslo.zip -d /usr/share/fonts/meslo/

sudo fc-cache -f -v
echo "done!"

#/usr/share/fonts/

zsh_in_docker.sh

#!/bin/sh
set -e

THEME=powerlevel10k/powerlevel10k
PLUGINS=""
ZSHRC_APPEND=""

while getopts ":t:p:a:" opt; do
    case ${opt} in
        t)  THEME=$OPTARG
            ;;
        p)  PLUGINS="${PLUGINS}$OPTARG "
            ;;
        a)  ZSHRC_APPEND="$ZSHRC_APPEND\n$OPTARG"
            ;;
        \?)
            echo "Invalid option: $OPTARG" 1>&2
            ;;
        :)
            echo "Invalid option: $OPTARG requires an argument" 1>&2
            ;;
    esac
done
shift $((OPTIND -1))

echo
echo "Installing Oh-My-Zsh with:"
echo "  THEME   = $THEME"
echo "  PLUGINS = $PLUGINS"
echo

check_dist() {
    (
        . /etc/os-release
        echo $ID
    )
}

check_version() {
    (
        . /etc/os-release
        echo $VERSION_ID
    )
}

install_dependencies() {
    DIST=`check_dist`
    VERSION=`check_version`
    echo "###### Installing dependencies for $DIST"

    if [ "`id -u`" = "0" ]; then
        Sudo=''
    elif which sudo; then
        Sudo='sudo'
    else
        echo "WARNING: 'sudo' command not found. Skipping the installation of dependencies. "
        echo "If this fails, you need to do one of these options:"
        echo "   1) Install 'sudo' before calling this script"
        echo "OR"
        echo "   2) Install the required dependencies: git curl zsh"
        return
    fi

    case $DIST in
        alpine)
            $Sudo apk add --update --no-cache git curl zsh
        ;;
        centos | amzn)
            $Sudo yum update -y
            $Sudo yum install -y git curl
            $Sudo yum install -y ncurses-compat-libs # this is required for AMZN Linux (ref: https://github.com/emqx/emqx/issues/2503) 
            $Sudo curl http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64/zsh-5.1-1.gf.el7.x86_64.rpm > zsh-5.1-1.gf.el7.x86_64.rpm
            $Sudo rpm -i zsh-5.1-1.gf.el7.x86_64.rpm
            $Sudo rm zsh-5.1-1.gf.el7.x86_64.rpm
        ;;
        *)
            $Sudo apt-get update
            $Sudo apt-get -y install git curl zsh locales
            if [ "$VERSION" != "14.04" ]; then
                $Sudo apt-get -y install locales-all
            fi
            $Sudo locale-gen en_US.UTF-8
    esac
}

zshrc_template() {
    _HOME=$1; 
    _THEME=$2; shift; shift
    _PLUGINS=$*;

    cat <<EOM
export LANG='en_US.UTF-8'
export LANGUAGE='en_US:en'
export LC_ALL='en_US.UTF-8'
export TERM=xterm

##### Zsh/Oh-my-Zsh Configuration
export ZSH="$_HOME/.oh-my-zsh"

ZSH_THEME="${_THEME}"
plugins=($_PLUGINS)

EOM
    printf "$ZSHRC_APPEND"
    printf "\nsource \$ZSH/oh-my-zsh.sh\n"
}

powerline10k_config() {
    cat <<EOM
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last"
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(user dir vcs status)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_STATUS_OK=false
POWERLEVEL9K_STATUS_CROSS=true
EOM
}

install_dependencies

cd /tmp

# Install On-My-Zsh
if [ ! -d $HOME/.oh-my-zsh ]; then
    sh -c "$(curl https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" --unattended
fi

# Generate plugin list
plugin_list=""
for plugin in $PLUGINS; do
    if [ "`echo $plugin | grep -E '^http.*'`" != "" ]; then
        plugin_name=`basename $plugin`
        git clone $plugin $HOME/.oh-my-zsh/custom/plugins/$plugin_name
    else
        plugin_name=$plugin
    fi
    plugin_list="${plugin_list}$plugin_name "
done

# Handle themes
if [ "`echo $THEME | grep -E '^http.*'`" != "" ]; then
    theme_repo=`basename $THEME`
    THEME_DIR="$HOME/.oh-my-zsh/custom/themes/$theme_repo"
    git clone $THEME $THEME_DIR
    theme_name=`cd $THEME_DIR; ls *.zsh-theme | head -1` 
    theme_name="${theme_name%.zsh-theme}"
    THEME="$theme_repo/$theme_name"
fi

# Generate .zshrc
zshrc_template "$HOME" "$THEME" "$plugin_list" > $HOME/.zshrc

# Install powerlevel10k if no other theme was specified
if [ "$THEME" = "powerlevel10k/powerlevel10k" ]; then
    git clone https://github.com/romkatv/powerlevel10k $HOME/.oh-my-zsh/custom/themes/powerlevel10k
    powerline10k_config >> $HOME/.zshrc
fi

how to use

start docker container

docker run -i -t -d  -v `pwd`:/moon/workspcae -p 12345:8888 abcdelf/anaconda3_ubuntu20_full:v0.4 /bin/bash

# for docker in doker
docker run -i -t -d -v /var/run/docker.sock:/var/run/docker.sock  -v /home/ubuntu/workspace:/home/moon/workspace -p 12345:8888 anaconda_ubuntu20_full:v0.4 zsh

jupyter

jupyter notebook --port 8888 --ip 0.0.0.0 --allow-root
jupyter lab --ip='*' --port=8888 --no-browser --allow-root

how to build this docker image


pip install xgboost lightgbm 
pip install esdk-obs-python --trusted-host pypi.org
pip install huaweicloud-sdk-python
pip install pydub django cryptography blaze flask

pip install pyarrow

config zsh

p10k configure

package installed

Package                       Version
----------------------------- -------------------
anyio                         2.0.2
argon2-cffi                   20.1.0
asgiref                       3.3.1
async-generator               1.10
attrs                         20.3.0
Babel                         2.9.0
backcall                      0.2.0
backports.functools-lru-cache 1.6.1
blaze                         0.10.1
bleach                        3.3.0
brotlipy                      0.7.0
certifi                       2020.12.5
cffi                          1.14.4
chardet                       4.0.0
click                         7.1.2
cryptography                  3.3.1
datashape                     0.5.2
debugpy                       1.2.1
decorator                     4.4.2
defusedxml                    0.6.0
deprecation                   2.1.0
Django                        3.1.6
entrypoints                   0.3
esdk-obs-python               3.20.11
Flask                         1.1.2
Flask-Cors                    3.0.10
huaweicloud-sdk-python        1.0.28
idna                          2.10
importlib-metadata            3.4.0
ipydrawio                     1.0.0a0
ipykernel                     5.1.0
ipython                       7.20.0
ipython-genutils              0.2.0
ipywidgets                    7.6.3
iso8601                       0.1.13
itsdangerous                  1.1.0
jedi                          0.17.2
Jinja2                        2.11.3
joblib                        1.0.0
json5                         0.9.5
jsonschema                    3.2.0
jupyter-client                6.1.11
jupyter-core                  4.7.1
jupyter-server                1.2.2
jupyterlab                    3.0.6
jupyterlab-code-formatter     1.4.3
jupyterlab-pygments           0.1.2
jupyterlab-server             2.1.3
jupyterlab-widgets            1.0.0
keystoneauth1                 3.4.0
lightgbm                      3.1.1
lxml                          4.6.2
MarkupSafe                    1.1.1
mistune                       0.8.4
multipledispatch              0.6.0
nbclassic                     0.2.6
nbclient                      0.5.1
nbconvert                     6.0.7
nbformat                      5.1.2
nest-asyncio                  1.4.3
networkx                      2.5
notebook                      6.2.0
numpy                         1.20.0
odo                           0.5.0
packaging                     20.8
pandas                        1.2.1
pandocfilters                 1.4.2
parso                         0.7.1
pbr                           5.5.1
pexpect                       4.8.0
pickleshare                   0.7.5
pip                           21.0.1
prometheus-client             0.9.0
prompt-toolkit                3.0.14
psutil                        5.8.0
ptyprocess                    0.7.0
pycparser                     2.20
pydub                         0.24.1
Pygments                      2.7.4
pyOpenSSL                     20.0.1
pyparsing                     2.4.7
pyrsistent                    0.17.3
PySocks                       1.7.1
python-dateutil               2.8.1
pytz                          2021.1
pyzmq                         22.0.1
requests                      2.25.1
scikit-learn                  0.24.1
scipy                         1.6.0
Send2Trash                    1.5.0
setuptools                    49.6.0.post20210108
six                           1.15.0
sniffio                       1.2.0
SQLAlchemy                    1.3.23
sqlparse                      0.4.1
stevedore                     3.3.0
terminado                     0.9.2
testpath                      0.4.4
threadpoolctl                 2.1.0
toolz                         0.11.1
tornado                       6.1
traitlets                     5.0.5
urllib3                       1.26.3
wcwidth                       0.2.5
webencodings                  0.5.1
Werkzeug                      1.0.1
wheel                         0.36.2
widgetsnbextension            3.5.1
xeus-python                   0.9.1
xgboost                       1.3.3
zipp                          3.4.0

How to use anaconda

Update conda

RUN conda update -n base -c defaults conda

Create app_env with python 3.6

RUN conda create -n app_env python=3.6

Create mpeg_env with python 3.8

RUN conda create -n mpeg_env python=3.8

Init conda

RUN conda init bash

Switch to mpeg_env then install ffmpeg

SHELL ["conda", "run", "-n", "ffmpeg_env", "/bin/bash", "-c"]
RUN conda install -y ffmpeg -c conda-forge

Switch to app_env then install Django && Django-Celery

SHELL ["conda", "run", "-n", "app_env", "/bin/bash", "-c"]
RUN pip install -r /requirements.txt