Skip to content

Instantly share code, notes, and snippets.

@ZJUGuoShuai
Created September 6, 2021 08:55
Show Gist options
  • Select an option

  • Save ZJUGuoShuai/a5d52eeaf544263df71685aedb5a61fa to your computer and use it in GitHub Desktop.

Select an option

Save ZJUGuoShuai/a5d52eeaf544263df71685aedb5a61fa to your computer and use it in GitHub Desktop.
Nexus 镜像制作(服务镜像、在线编程镜像还没做)
# NexusNet 镜像(CUDA 11.4,要求 Nvidia 驱动版本 >=470.57.02)
# 作者:郭帅
# =====================================================================================
# [1] nexus-base :编译 NexusNet 源码所需的环境,包括 CUDA/cuDNN/OpenCV/Protobuf 以及其他软件
FROM nvidia/cuda:11.4.1-cudnn8-devel-ubuntu20.04 AS nexus-base
# 更改 APT 源为阿里镜像站
RUN echo "\
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse\n\
" > /etc/apt/sources.list
# 删除 Nvidia 相关软件仓库
RUN rm /etc/apt/sources.list.d/*
# 安装 Git、Wget、Python3-pip 和 gcc-9/g++-9
RUN apt-get update \
&& apt-get install -y git wget python3-pip gcc-9 g++-9 \
&& rm -rf /var/lib/apt/lists/*
# 安装 CMake
RUN python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --no-cache-dir cmake
# 克隆 NexusNet、OpenCV 4.5.3 以及 Protobuf 3.16.0 代码
WORKDIR /root
RUN git clone http://10.214.192.178/guoshuai/opencv-mirror.git &&\
git clone http://10.214.192.178/guoshuai/protobuf-mirror.git
# 编译 OpenCV 并安装到系统
RUN mkdir opencv-build && cd opencv-build \
&& cmake -DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_LIST=core,imgcodecs,imgproc,highgui \
-DBUILD_PROTOBUF=OFF \
-DBUILD_JAVA=OFF \
-DWITH_IPP=OFF \
-DWITH_QUIRC=OFF \
-DWITH_ADE=OFF \
../opencv-mirror \
&& make -j \
&& make install \
&& cd .. && rm -rf opencv-build && rm -rf opencv-mirror
# 编译 Protobuf 并安装到系统
RUN mkdir protobuf-build && cd protobuf-build \
&& cmake -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-Dprotobuf_BUILD_TESTS=OFF \
-Dprotobuf_BUILD_PROTOC_BINARIES=OFF \
../protobuf-mirror/cmake \
&& make -j \
&& make install \
&& cd .. && rm -rf protobuf-build && rm -rf protobuf-mirror
# ==================================================================
# [2] nexus-dev :NexusNet 开发镜像,包含 NexusNet 源码,用于 Nexus 内部开发人员
FROM nexus-base AS nexus-dev
# 安装 SSH Server、Zsh 以及 oh-my-zsh
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt install -y openssh-server zsh \
&& rm -rf /var/lib/apt/lists/* \
&& REPO=sjtug/ohmyzsh REMOTE=https://git.sjtu.edu.cn/${REPO}.git sh -c \
"$(wget -O- https://git.sjtu.edu.cn/sjtug/ohmyzsh/-/raw/master/tools/install.sh\?inline\=false)"
# 克隆 Nexus 源码仓库
ARG gitlab_username=guoshuai
ARG gitlab_passwd=guoshuai123
RUN git clone http://$gitlab_username:$gitlab_passwd@10.214.192.178/lifei/sfz.git
# 编译 Nexus 及其测试程序
RUN mkdir -p sfz/build && cd sfz/build \
&& cmake .. \
&& make -j
# ================================================================================
# [3] nexus :NexusNet 发行版镜像,仅包含 NexusNet 头文件和 libnexus.so,给 Nexus 用户
FROM nexus-base AS nexus
# 获取 NexusNet Release 版本源码
WORKDIR /root
RUN wget --progress=bar:force:noscroll http://10.214.192.178/guoshuai/nexusnet-release/-/archive/master/nexusnet-release-master.tar.gz \
&& tar xf nexusnet-release-master.tar.gz
# 将 libnexus.so 放进来
COPY --from=nexus-dev /root/sfz/build/libnexus.so /usr/lib
# ================== 以下是用于 ZJUAI 的镜像 ====================
# =============================================================
# [4] rt :将 libnexus.so 移动到 ubuntu 中,是运行(不开发)的基础镜像
FROM ubuntu:20.04 AS nexus-rt
COPY --from=nexus-dev /root/sfz/build/libnexus.so /usr/lib
RUN apt-get update \
&& apt-get install -y libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# xxx 训练镜像:将 zjuai-xxx 移动到 nexus-rt 中
FROM nexus-rt AS zjuai-train
RUN mkdir /workspace \
&& apt-get update \
&& apt-get install -y python3 \
&& rm -rf /var/lib/apt/lists/* \
&& ln -s /usr/bin/python3 /usr/bin/python
COPY ./zjuai-googlenet /workspace
COPY ./main.py /workspace
CMD ["python3" "/workspace/main.py"]
# resnet 服务镜像
# 在线编程镜像
@ZJUGuoShuai

Copy link
Copy Markdown
Author

Nexus 镜像

使用 Dockerfile 进行多层、分阶段构建,能够提高构建速度、减少空间占用,且更容易维护。

内部人员开发镜像

构建:

docker build --target nexus-dev -t nexus-dev .

第一次从头构建可能时间较长(需编译 OpenCV、Protobuf 以及 Nexus),请耐心等待。

运行:

docker run \
  --gpus all \
  -itd \
  -v $(pwd)/data:/data \
  -p 22222:22 \
  --name nexus-dev \
  nexus-dev:latest bash

进入后,将 root 密码去除:

passwd -d root

然后修改 /etc/ssh/sshd_config 文件,将相应配置修改为:

PermitRootLogin yes
PasswordAuthentication yes
PermitEmptyPasswords yes

然后启动 SSH Server:

service ssh start

然后就可以 VS Code 或其他 IDE 无密码远程连接这个容器了。

发行版镜像

构建:

docker build --target release -t nexusnet .

ZJUAI 训练镜像

首先构建基本运行时镜像:

docker build --target nexus-rt -t nexus-rt .

构建:

docker build --target resnet-train -t nn-resnet-train:cuda114 .

ZJUAI 服务镜像

ZJUAI 在线编程镜像

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment