Docker实践——Dockerfile编写
2021-02-27 本文已影响0人
侠之大者_7d3f
Dockerfile
FROM nvidia/cuda:10.2-cudnn8-runtime-ubuntu18.04
LABEL author="xxxxxx"
# reference: https://blog.csdn.net/gandongusa/article/details/104598860/
# 修改ubuntu为阿里源
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
RUN apt-get -y clean \
&& apt-get -y update --fix-missing \
&& apt-get -y upgrade
# 非交互模式
ENV DEBIAN_FRONTEND noninteractive
# 下载必要的软件
# RUN apt-get install -y apt-utils sudo vim iproute2 wget
RUN apt-get install -y apt-utils sudo git nano wget openssh-server cmake build-essential \
&& apt-get -y autoclean \
&& apt-get -y autoremove
# Miniconda
COPY Miniconda3-py38_4.9.2-Linux-x86_64.sh /opt
RUN /bin/bash /opt/Miniconda3-py38_4.9.2-Linux-x86_64.sh -b -p /opt/miniconda3
# & rm -rf /opt/Miniconda3-py38_4.9.2-Linux-x86_64.sh
# ENV CONDA_HOME=/opt/miniconda3
# Add user
RUN useradd -ms /bin/bash xxx \
&& adduser xxx sudo \
&& echo "xxx:0000"|chpasswd \
&& echo "root:0000"|chpasswd
# Set User
ENV HOME=/home/wei
ENV HSOTNAME=dell-vostro
ENV DEBIAN_FRONTEND=noninteractive
# # workdir
WORKDIR /home/xxx
USER xxx
# 添加conda变量到PATH
RUN echo '\n\
__conda_setup="$('/opt/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"\n\
if [ $? -eq 0 ]; then\n\
eval "$__conda_setup"\n\
else\n\
if [ -f "/opt/miniconda3/etc/profile.d/conda.sh" ]; then\n\
. "/opt/miniconda3/etc/profile.d/conda.sh"\n\
else\n\
export PATH="/opt/miniconda3/bin:$PATH"\n\
fi\n\
fi\n\
unset __conda_setup\n'\
>> ~/.bashrc
# 修改pip 源
RUN mkdir ~/.pip && \
cd ~/.pip && \
echo "\
[global]\n\
index-url = https://mirrors.aliyun.com/pypi/simple/\n\
\n\
[install]\n\
trusted-host=mirrors.aliyun.com\n"\
> ~/.pip/pip.conf
ENV PIP=/opt/miniconda3/bin/pip PIP_URL=https://mirrors.aliyun.com/pypi/simple/
RUN $PIP install numpy -i $PIP_URL \
&& $PIP install numpy -i $PIP_URL \
&& $PIP install opencv-python -i $PIP_URL \
&& $PIP install torchvision -i $PIP_URL \
&& $PIP install torchaudio -i $PIP_URL \
&& $PIP install torchtext -i $PIP_URL \
&& $PIP install onnxruntime-gpu -i $PIP_URL \
&& $PIP install tensorflow==2.3.0 -i $PIP_URL
# 设置容器运行时执行的命令,启动ssh服务,并进入bash Shell
ENTRYPOINT sudo service ssh start && /bin/bash
# pip pkgs
# COPY ./*.whl Backup/wheel_pkgs/
# SHELL ["/bin/bash", "-c"]
# RUN /bin/bash -c "source ~/.bashrc" \
# && which pip \
# && which python \
# && pip install numpy
# RUN which pip \
# && which python
# # pytroch
# RUN pip install torch torchvision \
# && pip install onnxruntime-gpu
# # 设置容器运行时执行的命令,启动ssh服务,并进入bash Shell
# ENTRYPOINT sudo service ssh start && /bin/bash