AI算法开发-dockerfile编写组件(快速编写你的Dockerfile)

2023-10-11 11:14:26 浏览数 (2)

LABEL

代码语言:javascript复制
LABEL maintainer "Yan Errol,CSDN:https://errol.blog.csdn.net/,微信公众号:三更两点"

FROM

建议采用官方的源作为基础的镜像.比如ubuntu官方源

ubuntu国内源更新

代码语言:javascript复制
RUN echo "deb http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse" > /etc/apt/sources.list &&
    echo "deb http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list &&
    echo "deb http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse" >>  /etc/apt/sources.list &&
    echo "deb http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse" >>  /etc/apt/sources.list

必装软件

代码语言:javascript复制
RUN apt update && apt install -y --no-install-recommends gcc make cmake git vim sudo htop openssh-server wget curl  ca-certificates &&
    apt install --fix-missing &&
    rm -rf /var/lib/apt/lists/*

安装openssh

代码语言:javascript复制
RUN mkdir /var/run/sshd && echo 'root:passwd' | chpasswd &&
    sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config  &&
    sed 's@sessionsrequiredspam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd &&
    echo "export VISIBLE=now" >> /etc/profile  &&
    echo "PermitRootLogin yes"  >>  /etc/ssh/sshd_config
CMD service ssh start

anaconda安装

代码语言:javascript复制
ARG PATH="/root/miniconda3/bin:${PATH}"
ENV PATH="/root/miniconda3/bin:${PATH}"
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh 
    && mkdir /root/.conda 
    && bash Miniconda3-latest-Linux-x86_64.sh -b 
    && rm -f Miniconda3-latest-Linux-x86_64.sh
    
ENV PATH /opt/conda/bin:$PATH
RUN conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ && conda install python=3.8 pip &&
    conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge &&
    conda clean -ya

pip 源更新

代码语言:javascript复制
RUN mkdir ~/.pip && touch ~/.pip/pip.conf
RUN echo"[global]" >> ~/.pip/pip.conf &&
   echo"index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> ~/.pip/pip.conf &&
   echo"[install]" >> ~/.pip/pip.conf &&
   echo"itrusted-host=mirrors.aliyun.com" >> ~/.pip/pip.conf &&

0 人点赞