FROM ubuntu:latest
LABEL author = 'ZHOU'
# 修改源为国内源
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 clean && apt-get update --fix-missing
# 更新系统
RUN apt-get update && apt-get upgrade
# 软件安装所必须的依赖时,有可能会出现对话框进行选择,如果不选择会导致镜像制作失败,需要添加如下语句
#+++++++++++++++++++
# 添加管理员账户ZHOU,设置工作目录
RUN useradd -ms /bin/bash zhou && \
adduser zhou sudo && \
echo "zhou:0"|chpasswd && \
echo "root:0"|chpasswd
# 设置运行账户,设置环境变量并容器启动后需要运行的命令
# 改变运行账户、工作目录和运行Shell(/bin/bash,默认Shell为/bin/sh)
ENV HOME /home/zhou
ENV HOSTNAME ZHOU-PC
WORKDIR /home/zhou
#+++++++++++++++++++
# 安装iproute2等的依赖时,会出现对话框,制作镜像时不选择会失败,解决方案是添加语句: ENV DEBIAN_FRONTEND noninteractive)
ENV DEBIAN_FRONTEND noninteractive
# 安装apt-utils(允许安装第三方软件)、sudo、vim、iproute2、wget(下载文件)
RUN apt-get install -y apt-utils sudo vim iproute2 wget
# ---------------------------------------
# 安装OpenSSH
RUN apt-get install -y openssh-server
# 修改ssh配置文件,文件位置/etc/ssh/sshd_config,添加允许所有主机连接,
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config && \
echo 'sshd:ALL' >> /etc/hosts.aldlow
# 开放22端口
EXPOSE 22
# ssh服务需要在容器启动时运行,一般由CMD或者ENTRYPOINT设置执行
# ---------------------------------------
# 安装完软件之后,自动清除缓存
RUN apt-get autoclean && apt-get autoremove
#++++++++++++++++++++
USER zhou
# 下载Miniconda
RUN wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/conda.sh
# 安装Miniconda, -b为静默安装,-p为指定安装目录,安装完成之后删除安装程序
RUN /bin/bash ~/conda.sh -b -p ~/conda && \
rm ~/conda.sh
# 添加conda变量到PATH
RUN echo '\n\
__conda_setup="$('/home/zhou/conda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"\n\
if [ $? -eq 0 ]; then\n\
eval "$__conda_setup"\n\
else\n\
if [ -f "/home/zhou/conda/etc/profile.d/conda.sh" ]; then\n\
. "/home/zhou/conda/etc/profile.d/conda.sh"\n\
else\n\
export PATH="/home/zhou/conda/bin:$PATH"\n\
fi\n\
fi\n\
unset __conda_setup\n'\
>> ~/.bashrc && \
/bin/bash -c 'source ~/.bashrc'
# 更改Python国内源
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
# 更改Conda国内源
RUN echo "\
channels:\n\
- defaults\n\
show_channel_urls: true\n\
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda\n\
default_channels:\n\
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main\n\
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free\n\
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r\n\
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro\n\
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2\n\
custom_channels:\n\
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n\
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n\
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n\
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n\
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n\
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n"\
> ~/.condarc
#+++++++++++++++++++
# 设置容器运行时执行的命令,启动ssh服务,并进入bash Shell
ENTRYPOINT sudo service ssh start && /bin/bash
#---------------------------------------------------------------------------------------
# 利用Dockerfile创建定制镜像,同时指定版本号
# docker build . -t mylinux:1.0
# 创建完成之后,利用docker run命令生成新的容器,同时把容器的22端口映射到宿主机的8888端口上,指定容器名、主机名等
# docker run -it -p 8888:22 --name Ubuntu_Conda -h ZHOU-PC mylinux:1.0
# 远程通过SSH连接到容器,需要知道宿主机的IP地址
# ssh -p 8888 [email protected]
#---------------------------------------------------------------------------------------