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

FROM $BASE_IMAGE
ARG BASE_IMAGE
chenpangpang's avatar
chenpangpang committed
5
6
LABEL module="vscode"
ARG DEBIAN_FRONTEND=noninteractive
chenpangpang's avatar
chenpangpang committed
7
8
9
10
11
12
13
# 是否基于torch镜像构建
ARG BASE_IMAGE_IS_TORCH=0
ARG TORCH_VERSION="2.0.1"
ARG TORCHVISION_VERSION="0.15.2"
ARG TORCHAUDIO_VERSION="2.0.2"
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
14
15
16
17
18
19
20
21
22
23
ENV TZ=Asia/Shanghai
ENV SHELL=/bin/bash \
    LC_ALL=en_US.UTF-8 \
    LANG=en_US.UTF-8 \
    LANGUAGE=en_US.UTF-8
ARG SOURCES="-i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn"
SHELL ["/bin/bash","-c"]
USER root
WORKDIR /tmp

chenpangpang's avatar
chenpangpang committed
24
ENV HF_ENDPOINT=https://hf-mirror.com
chenpangpang's avatar
chenpangpang committed
25
26
27

COPY ./python-requirements.txt /tmp/

chenpangpang's avatar
chenpangpang committed
28
29
30
31
COPY ./code-server_4.22.1_amd64.deb ./
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak \
&& mv /etc/apt/sources.list.d /etc/apt/sources.list.d.bak \
&& version_codename=$(cat /etc/os-release | grep -i 'VERSION_CODENAME' | awk -F= '{print $2}') \
chenpangpang's avatar
chenpangpang committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
&& echo -e "deb http://mirrors.aliyun.com/ubuntu/ ${version_codename} main restricted universe multiverse \n\
deb http://mirrors.aliyun.com/ubuntu/ ${version_codename}-security main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ ${version_codename}-updates main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ ${version_codename}-proposed main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ ${version_codename}-backports main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ ${version_codename} main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ ${version_codename}-security main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ ${version_codename}-updates main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ ${version_codename}-proposed main restricted universe multiverse\n\
deb-src http://mirrors.aliyun.com/ubuntu/ ${version_codename}-backports main restricted universe multiverse" > /etc/apt/sources.list \
    && apt-get update -y \
    && apt-get install --no-install-recommends -y \
    openssl \
    libssl-dev \
    net-tools \
    locales \
    wget \
    git \
    sudo \
    openssh-client \
    openssh-server \
    && locale-gen en_US.UTF-8 \
chenpangpang's avatar
chenpangpang committed
54
55
56
57
58
59
    && dpkg -i code-server_4.22.1_amd64.deb \
    #&& apt-get clean \
    #&& rm -rf /var/lib/apt/lists/* \
    #&& rm -rf /tmprm \
    #&& mv /etc/apt/sources.list.bak /etc/apt/sources.list \
    #&& mv /etc/apt/sources.list.d.bak /etc/apt/sources.list.d \
chenpangpang's avatar
chenpangpang committed
60
61
62
63
    && mkdir -p /var/run/sshd \
    && ssh-keygen  -A \
    && sed -i "s/#UseDNS .*/UseDNS no/" /etc/ssh/sshd_config

chenpangpang's avatar
chenpangpang committed
64
# ----- conda and python install -----
chenpangpang's avatar
chenpangpang committed
65

chenpangpang's avatar
chenpangpang committed
66
67
68
69
70
71
72
73
RUN if [ -n "$CONDA_URL" ];then \
    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
chenpangpang's avatar
chenpangpang committed
74

chenpangpang's avatar
chenpangpang committed
75
ENV PATH=$PATH:/opt/conda/bin
chenpangpang's avatar
chenpangpang committed
76

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

chenpangpang's avatar
chenpangpang committed
82
83
84
85
86
87
88
89
90
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 \
    && rm -r /root/.cache/pip; fi
chenpangpang's avatar
chenpangpang committed
91

chenpangpang's avatar
chenpangpang committed
92
93
94
95
96
97
98
99
100
101
102
RUN if [ -n "$TORCH_VERSION" ];then \
    pip install --no-cache-dir transformers accelerate diffusers; fi

COPY ./python-requirements.txt /tmp/
RUN pip install --no-cache-dir -r /tmp/python-requirements.txt

### 添加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
chenpangpang's avatar
chenpangpang committed
103
104


chenpangpang's avatar
chenpangpang committed
105
EXPOSE 8080