Dockerfile.jupyterlab_ubuntu 9.42 KB
Newer Older
chenpangpang's avatar
chenpangpang committed
1
2
3
4
5
6
ARG BASE_IMAGE="nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu20.04"

FROM $BASE_IMAGE
ARG BASE_IMAGE
ARG DEBIAN_FRONTEND=noninteractive
LABEL module="jupyter"
chenpangpang's avatar
chenpangpang committed
7
8

# ----- torch args -----
chenpangpang's avatar
chenpangpang committed
9
10
# 是否基于torch镜像构建
ARG BASE_IMAGE_IS_TORCH=0
chenpangpang's avatar
chenpangpang committed
11
12
13
14
15
16
ARG TORCH_VERSION
ARG TORCHVISION_VERSION
ARG TORCHAUDIO_VERSION

# ----- tensorflow args -----
ARG TENSORFLOW_VERSION
chenpangpang's avatar
chenpangpang committed
17
18
19
20
21
22
23
24
25
26
27
ARG IMAGE_TAG

#ARG CONDA_URL="https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_24.7.1-0-Linux-x86_64.sh"
# ----- paddlepaddle args -----
ARG PADDLEPADDLE_VERSION
ARG PADDLENLP_VERSION
ARG CUDA_VERSION
ARG PADDLE_URL
# ----- conda and python args ----
ARG CONDA_URL
#ARG CONDA_URL="https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_24.7.1-0-Linux-x86_64.sh"
chenpangpang's avatar
chenpangpang committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
ARG SOURCES="-i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn"
ENV TZ=Asia/Shanghai
ENV SHELL=/bin/bash \
    LC_ALL=en_US.UTF-8 \
    LANG=en_US.UTF-8 \
    LANGUAGE=en_US.UTF-8
ENV HF_ENDPOINT=https://hf-mirror.com
SHELL ["/bin/bash","-c"]
USER root

RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak \
    && mv /etc/apt/sources.list.d /etc/apt/sources.list.d.bak \
    && version_id=$(cat /etc/os-release | grep -i 'VERSION_CODENAME' | awk -F= '{print $2}') \
    && echo -e "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id} main restricted universe multiverse \n\
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id}-security main restricted universe multiverse\n\
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id}-updates main restricted universe multiverse\n\
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id}-proposed main restricted universe multiverse\n\
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id}-backports main restricted universe multiverse\n\
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id} main restricted universe multiverse\n\
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id}-security main restricted universe multiverse\n\
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id}-updates main restricted universe multiverse\n\
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id}-proposed main restricted universe multiverse\n\
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_id}-backports main restricted universe multiverse" > /etc/apt/sources.list \
    && apt-get update -y \
chenpangpang's avatar
chenpangpang committed
52
    && apt-get install --no-install-recommends -y vim openssl libssl-dev net-tools locales wget git git-lfs sudo openssh-client openssh-server libaio-dev \
chenpangpang's avatar
chenpangpang committed
53
54
    && locale-gen en_US.UTF-8 

chenpangpang's avatar
chenpangpang committed
55
# ----- conda and python install -----
chenpangpang's avatar
chenpangpang committed
56

chenpangpang's avatar
chenpangpang committed
57
RUN if [ -n "$CONDA_URL" ];then \
chenpangpang's avatar
chenpangpang committed
58
59
60
61
62
63
64
65
66
67
    mkdir -p /tmp/conda-extension \
    && cd /tmp/conda-extension \
    && wget $CONDA_URL \
    && bash $(echo $CONDA_URL | awk -F "/" '{print $NF}') -b -p /opt/conda \
    && echo "export PATH=\$PATH:/opt/conda/bin" >> /etc/profile.d/sothisai.sh \
    && cd .. \
    && rm -rf /tmp/conda-extension; fi

ENV PATH=$PATH:/opt/conda/bin

chenpangpang's avatar
chenpangpang committed
68
RUN pip3 install --upgrade pip ${SOURCES} || pip install --upgrade pip ${SOURCES} \
chenpangpang's avatar
chenpangpang committed
69
70
    && pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
    && mv /etc/apt/sources.list.bak /etc/apt/sources.list \
chenpangpang's avatar
chenpangpang committed
71
72
    && mv /etc/apt/sources.list.d.bak /etc/apt/sources.list.d

chenpangpang's avatar
chenpangpang committed
73
74
75
76
77
78
79
80
RUN if [ -n "$TORCH_VERSION" ] && [ $BASE_IMAGE_IS_TORCH -eq 0 ];then \
    cuda_version=$(echo "$BASE_IMAGE" | awk -F'[:-]' '{n=split($2,a,"."); print a[1] a[2]}') \
    && if [ "${TORCH_VERSION%%.*}" -eq 1 ]; then \
    pip3 install --no-cache-dir "numpy<2" \
    && pip3 install --no-cache-dir  torch==$TORCH_VERSION+cu$cuda_version torchvision==$TORCHVISION_VERSION+cu$cuda_version torchaudio==$TORCHAUDIO_VERSION \
    --extra-index-url https://download.pytorch.org/whl/cu$cuda_version;else \
    pip3 install --no-cache-dir torch==$TORCH_VERSION torchvision==$TORCHVISION_VERSION torchaudio==$TORCHAUDIO_VERSION \
    --index-url https://download.pytorch.org/whl/cu$cuda_version; fi \
chenpangpang's avatar
chenpangpang committed
81
82
    && rm -r /root/.cache/pip; fi

chenpangpang's avatar
chenpangpang committed
83
84
85
86
RUN if [ -n "$TORCH_VERSION" ];then \
    pip install --no-cache-dir transformers accelerate diffusers; fi

RUN if [ -n "$TENSORFLOW_VERSION" ]; then \
chenpangpang's avatar
chenpangpang committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    tf_version_minor=$(echo $TENSORFLOW_VERSION | cut -d'.' -f1-2 ); \
    [ "$tf_version_minor" == "2.13" ] || [ "$tf_version_minor" == "2.18" ] && tensorflow_text_version=$tf_version_minor.0rc0 || tensorflow_text_version=$tf_version_minor.*; \
    pip install --no-cache-dir tensorflow==$TENSORFLOW_VERSION  -i https://pypi.org/simple/ && \
    pip install --no-cache-dir tensorflow-text==$tensorflow_text_version tensorflow-hub; fi

    # 2.16.1必须手动添加环境变量
RUN if [ $TENSORFLOW_VERSION == "2.16.1" ]; then \
    python_version=$(echo $IMAGE_TAG | awk -F'[-:]' '{for(i=3;i<=NF;i++) if($i ~ /^py[0-9]+\.[0-9]+$/) {gsub(/^py/,"",$i); print $i; exit}}') && \
    CUDNN_PATH=/opt/conda/lib/python$python_version/site-packages/nvidia/cudnn && \
    echo "export CUDNN_PATH=$CUDNN_PATH" >> /etc/bash.bashrc && \
    echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDNN_PATH/lib:/usr/local/cuda/lib64" >> /etc/bash.bashrc;fi && \
    if [  $TENSORFLOW_VERSION == "2.8.0" ] || [  $TENSORFLOW_VERSION == "2.7.0" ] || [  $TENSORFLOW_VERSION == "2.6.0" ]; then \
        pip install --no-cache-dir protobuf==3.20.*;fi && \
    if [  $TENSORFLOW_VERSION == "2.4.0" ] || [  $TENSORFLOW_VERSION == "2.5.0" ] || [  $TENSORFLOW_VERSION == "2.6.0" ]; then \
        pip install --no-cache-dir numpy==1.19.2 matplotlib==3.6.*;fi && \
    if [  $TENSORFLOW_VERSION == "2.8.0" ] || [  $TENSORFLOW_VERSION == "2.10.0" ] || [  $TENSORFLOW_VERSION == "2.11.0" ] || [  $TENSORFLOW_VERSION == "2.9.0" ] || [  $TENSORFLOW_VERSION == "2.9.3" ] || [  $TENSORFLOW_VERSION == "2.14.0" ]; then \
        pip install --no-cache-dir "numpy<2"; fi

# ----- paddlepaddle install -----
RUN if [ -n "$PADDLEPADDLE_VERSION" ] && [ -n "$PADDLE_URL" ]; then \
chenpangpang's avatar
chenpangpang committed
107
108
109
110
111
112
113
114
115
    if [ "$(echo -e "$PADDLEPADDLE_VERSION\n3.0" | sort -V | head -n1)" = "3.0" ]; then \
        # 处理 PADDLEPADDLE_VERSION >= 3.0 的情况
        pip install paddlepaddle-gpu==$PADDLEPADDLE_VERSION -f $PADDLE_URL -i $PADDLE_URL && \
        rm -r /root/.cache/pip; \
    else \
        # 处理 PADDLEPADDLE_VERSION < 3.0 的情况
        pip install paddlepaddle-gpu==$PADDLEPADDLE_VERSION -f $PADDLE_URL && \
        rm -r /root/.cache/pip; \
    fi; \
chenpangpang's avatar
chenpangpang committed
116
117
118
119
120
121
122
123
fi

RUN if [ -n "$PADDLEPADDLE_VERSION" ] && [ -z "$PADDLE_URL" ]; then \
    pip install paddlepaddle-gpu==$PADDLEPADDLE_VERSION -i https://pypi.tuna.tsinghua.edu.cn/simple \
    && rm -r /root/.cache/pip; \
fi

RUN if [ -n "$PADDLENLP_VERSION" ] ; then \
chenpangpang's avatar
chenpangpang committed
124
125
126
127
128
129
130
131
132
133
134
135
    if [ -n "$PADDLEPADDLE_VERSION" ] && \
       [ "$(echo -e "$PADDLEPADDLE_VERSION\n2.3" | sort -V | head -n1)" = "2.3" ]; then \
        # 处理 PADDLEPADDLE_VERSION >= 2.3 的情况
        pip install paddlenlp==$PADDLENLP_VERSION ppdiffusers huggingface_hub==0.25.0 --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple && \
        rm -r /root/.cache/pip; \
    else \
        # 处理 PADDLEPADDLE_VERSION < 2.3 的情况
        pip install paddlenlp==$PADDLENLP_VERSION numpy==1.19.5 protobuf==3.20.3 --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple && \
        # 替换小于2.3版本中np.object为object
        sed -i 's/np\.object/object/g' /opt/conda/lib/python3.*/site-packages/paddle/**/*.py && \
        rm -r /root/.cache/pip; \
    fi; \
chenpangpang's avatar
chenpangpang committed
136
fi
chenpangpang's avatar
chenpangpang committed
137

chenpangpang's avatar
chenpangpang committed
138

chenpangpang's avatar
chenpangpang committed
139
140
141
COPY ./python-requirements.txt /tmp/
RUN pip install --no-cache-dir -r /tmp/python-requirements.txt

chenpangpang's avatar
chenpangpang committed
142
143
144
145
146
147
148
### 添加HF的镜像变量
ENV HF_ENDPOINT=https://hf-mirror.com
RUN echo 'export HF_ENDPOINT=https://hf-mirror.com' >> /etc/bash.bashrc && \
    echo 'export HF_ENDPOINT=https://hf-mirror.com' >> ~/.bashrc && \
    echo 'export CUDA_HOME=/usr/local/cuda' >> /etc/bash.bashrc

# 安装jupyterlab插件, 生成sshd配置
chenpangpang's avatar
chenpangpang committed
149
150
RUN pip3 install jupyterlab==4.0.0
RUN mkdir -p /tmp/jupyter-extension
chenpangpang's avatar
chenpangpang committed
151
COPY ./jupyter_ext_model-1.0.10-py3-none-any.whl /tmp/jupyter-extension/
chenpangpang's avatar
chenpangpang committed
152
COPY ./jupyter_ext_platform-1.0.14-py3-none-any.whl /tmp/jupyter-extension/
chenpangpang's avatar
chenpangpang committed
153
COPY ./jupyterlab_language_pack_zh_cn-4.0.post6-py2.py3-none-any.whl /tmp/jupyter-extension/
chenpangpang's avatar
chenpangpang committed
154
COPY ./git_lfs-1.6-py2.py3-none-any.whl /tmp/jupyter-extension/
chenpangpang's avatar
chenpangpang committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
COPY ./requirements.txt /tmp/jupyter-extension/
COPY ./static /tmp/jupyter-extension/static
COPY extension.sh /tmp/
RUN chmod +x /tmp/extension.sh && \
    /tmp/extension.sh

COPY ./jupyter_lab_config.py /etc/
RUN jupytersite="$(python3 -m pip show jupyterlab | grep -i '^location' | awk '{print $2}')" \
    && JUPYTERLAB_DIR=$(echo ${jupytersite%%/lib/python*}) \
    && if [[ ${JUPYTERLAB_DIR}/bin/jupyter != "/opt/conda/bin/jupyter" ]]; \
    then mkdir -p /opt/conda/bin; \
    ln -sf ${JUPYTERLAB_DIR}/bin/jupyter /opt/conda/bin/jupyter;fi \
    && echo "export JUPYTER_CONFIG_PATH=/etc" >> /etc/bash.bashrc \
    && echo "export JUPYTER=${JUPYTERLAB_DIR}/bin/jupyter" >> /etc/bash.bashrc\
    && echo "export PATH=${JUPYTERLAB_DIR}/bin:${PATH}" >> /etc/bash.bashrc \
    && mkdir -p /var/run/sshd \
    && ssh-keygen  -A \
    && sed -i "s/#UseDNS .*/UseDNS no/" /etc/ssh/sshd_config

chenpangpang's avatar
chenpangpang committed
174
175
176
177
178
179
180
181
182
183
184
185
186
# RUN echo "source /usr/local/bin/fastpt -E  > /dev/null 2>&1" >> /etc/bash.bashrc

RUN /bin/bash -c "source /usr/local/bin/fastpt -E" && echo 'source /etc/bashrc' >> /etc/profile.d/custom.sh

ENV FASTPT_TORCH_LIB_PATH=/usr/local/lib/python3.10/dist-packages/torch/lib

ENV FASTPT_CUDA_LIB_PATH=/opt/dtk/cuda/cuda-12/lib64

ENV LD_LIBRARY_PATH=$FASTPT_TORCH_LIB_PATH:$LD_LIBRARY_PATH

ENV LD_LIBRARY_PATH=$FASTPT_CUDA_LIB_PATH:$LD_LIBRARY_PATH


chenpangpang's avatar
chenpangpang committed
187
188
189
190
EXPOSE 8888