type
status
date
slug
summary
tags
category
icon
password
comment
包括 Docker 构建,Docke 部署以及Jupyter Lab安装
编写 Dockerfile
# Use the official Python 3.7.5 image as the base image. FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu20.04-torch2.3-onnxruntime1.18 # 维护者信息 LABEL maintainer="yeziyang <yeziyang@163.com>" LABEL description="This example Dockerfile installs python and run ADC." USER root # 设置工作目录 WORKDIR /work/ # 复制当前目录的所有内容到容器的工作目录中 # COPY . /work/ # 替换默认的APT源为清华大学镜像源 RUN sed -i s@/deb.debian.org@/mirrors.tuna.tsinghua.edu.cn@g /etc/apt/sources.list && \ sed -i s@/security.debian.org@/mirrors.tuna.tsinghua.edu.cn@g /etc/apt/sources.list && \ cat /etc/apt/sources.list RUN apt-get clean && \ apt-get update && \ apt-get install -y vim libgl1-mesa-glx libglib2.0-0 # 安装 Python 3.8 # RUN apt-get install -y python3.8 python3.8-dev python3-pip # 创建符号链接,将 python3.8 和 python3 指向新安装的版本 # RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 # 使用 pip 安装项目依赖项 # RUN pip3 install --no-cache-dir --upgrade pip -i https://mirrors.aliyun.com/pypi/simple #RUN pip3 install torch==1.12.0+cu116 torchvision==0.13.0+cu116 torchaudio==0.12.0 --extra-index-url https://download.pytorch.org/whl/cu116 # RUN pip3 install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple # RUN pip3 install --no-cache-dir /root/packages/* -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html # RUN pip3 install --no-cache-dir paddlepaddle-gpu==2.5.2.post116 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html #RUN pip3 install --no-cache-dir minio==7.1.0 -i https://mirrors.aliyun.com/pypi/simple #RUN pip3 install --no-cache-dir kafka-python==2.0.2 -i https://mirrors.aliyun.com/pypi/simple # 清理不必要的包 RUN apt-get clean && rm -rf /var/lib/apt/lists/* RUN rm -rf /root/packages # 启动程序 # CMD ["sh", "./run.sh"] CMD ["bash"]
编写 Docker 构建脚本
#!/bin/bash set -ex export DOCKER_BUILDKIT=1 docker build --no-cache --tag yzy_test:1.0 .
查看Docker镜像是否构建成功
docker images yzy_test
删除镜像
docker -rmi yzy_test:1.0
保存Docker镜像到本地
docker save yzy_test:1.0 -o yzy_test.tar
在Linux服务器上加载镜像yzy_test.tar
docker load -i yzy_test.tar
启动Docker容器
docker run -itd --shm-size=4g -p 9014:9014 -p 9015:9015 -p 9016:9016 -v /data/zeta_algorithm/yzy/work:/work --name yzy_ai yzy_work:1.0 /bin/bash
进入到Docker容器
docker exec -it ai /bin/bash
退出Docker容器
exit -d
创建 python 虚拟环境
python3 -m venv myenv source myenv/bin/activate
安装Jupyter Lab
- 安装Jupyter Lab
pip install jupyterlab
- 编写Jupyter Lab后台启动脚本
jupyter_start.sh
nohup jupyter lab --ip='*' --port=9016 --no-browser --allow-root --notebook-dir=/work > jupyterlab.log 2>&1 &