目录
说明:离线安装,也需要在线下载所有组件和依赖包后,拷贝到离线环境,去制作镜像。建议在线制作,因为在线可以自动下载所有组件,不会因为缺少组件或依赖,导致制作的镜像出现问题。文档包含离线和在线安装命令,请根据需要进行使用。
文档中的组件版本,都是示例,请根据需要,进行安装和更新版本。文档中的Dockerfile只提供安装openssh、jupyter和python组件,是为了适配AI平台,如果FROM镜像中,有python3可以屏蔽安装python3的部分命令。
注意:jupyterlab必须使用python3及以上版本,如果使用python2,不建议安装jupyterlab,或者自己去找jupyter早期版本,根据需要进行修改。文档中的Dockerfile只支持python3的jupyterlab安装,不支持python2.
如果没有最终失败,Dockerfile在线制作镜像输出的红色内容,请忽略,不影响最终制作的镜像
一、Centos7系统
1.1 Dockerfile安装组件
Dockerfile下载链接:
https://github.com/wjyzzu/inpsur-dockerfile/tree/main/base/centos
Dockerfile文件内容:
#base image
FROM centos:latest
MAINTAINER wjy
# install openssh and openssl
RUN set -ex \
&& yum install -y openssh-clients openssh-server openssl \
&& mkdir -p /var/run/sshd \
&& /usr/bin/ssh-keygen -A
# Allow OpenSSH to talk to containers without asking for confirmation
RUN set -ex \
&& cat /etc/ssh/ssh_config | grep -v StrictHostKeyChecking > /etc/ssh/ssh_config.new \
&& echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config.new \
&& cat /etc/ssh/sshd_config | grep -v PermitRootLogin> /etc/ssh/sshd_config.new \
&& echo "PermitRootLogin yes" >> /etc/ssh/sshd_config.new \
&& mv /etc/ssh/ssh_config.new /etc/ssh/ssh_config \
&& mv /etc/ssh/sshd_config.new /etc/ssh/sshd_config
# start install python3
## python version
ARG python=3.6.11
ENV PYTHON_VERSION=${python}
RUN yum clean packages \
&& yum -y install wget make zlib zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel gdbm-devel gcc libffi-devel \
&& cd /home \
&& wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz \
&& tar -zxvf Python-${PYTHON_VERSION}.tgz \
&& cd Python-${PYTHON_VERSION} \
&& ./configure \
&& make \
&& make install \
&& make clean \
&& rm -rf Python-${PYTHON_VERSION}
## set python3
RUN set -ex \
&& if [ -e /usr/bin/python ]; then mv /usr/bin/python /usr/bin/python27; fi \
&& if [ -e /usr/bin/pip ]; then mv /usr/bin/pip /usr/bin/pip-python27; fi \
&& ln -s /usr/local/bin/python3 /usr/bin/python \
&& ln -s /usr/local/bin/pip3 /usr/bin/pip
# modify configuration
RUN set -ex \
&& sed -i "s#/usr/bin/python#/usr/bin/python2.7#" /usr/bin/yum \
&& if [ -e /usr/libexec/urlgrabber-ext-down ]; then sed -i "s#/usr/bin/python#/usr/bin/python2.7#" /usr/libexec/urlgrabber-ext-down; fi
# end install python3
# install jupyterlab
RUN set -ex \
&& pip install --upgrade pip \
&& pip --no-cache-dir install jupyterlab \
&& rm -rf /root/.cache/pip/http/*
## configure jupyterlab
RUN set -ex \
&& mkdir /etc/jupyter/ \
&& wget -P /etc/jupyter/ https://raw.githubusercontent.com/Winowang/jupyter_gpu/master/jupyter_notebook_config.py \
&& wget -P /etc/jupyter/ https://raw.githubusercontent.com/Winowang/jupyter_gpu/master/custom.js
## tini
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
- (1)根据制作情况,修改FROM中的基础镜像
- (2)如果需要指定python3版本,可以在build时使用--build-arg python=3.7.9类似命令修改版本,默认python版本3.6.11,示例:
docker build --build-arg python=3.7.9 -t centos7.4-cuda9.0-cudnn7.0-base-inspur:latest -f /home/wjy/image_components/Dockerfile .
(3)同时,可以修改Dockerfile文件,指定jupyterlab版本,双等号后面指定版本jupyterlab==2.2.9,示例:
pip --no-cache-dir install jupyterlab==2.2.9
1.2 手动安装组件
1.2.1 在线安装
在线安装组件命令,Dockerfile文件里面都有,根据需要,docker run进入容器,执行相应命令,进行手动在线安装。