docker启动项目环境搭建

This commit is contained in:
yanyuxiyangzk@126.com 2024-04-04 13:47:49 +08:00
parent f83d29620b
commit fa08d4f670
3 changed files with 131 additions and 1 deletions

2
app.py
View File

@ -95,7 +95,7 @@ def txt_to_audio(text_):
text_,
gspeaker,
"zh-cn", #en args.language,
"http://localhost:9000", #args.server_url,
"http://192.168.1.3:9000", #args.server_url,
"20" #args.stream_chunk_size
),
nerfreal

56
llm/Dockerfile Normal file
View File

@ -0,0 +1,56 @@
# 使用NVIDIA的CUDA基础镜像
#FROM nvidia/cuda:11.3.0-cudnn8-runtime-ubuntu18.04
#FROM m11007322/cuda11.3.0-cudnn8-devel-ubuntu20.04-jupyterlab
FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04
# 安装Python和pip
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
# 安装Jupyter
RUN pip3 install --no-cache-dir jupyter
# 安装基础工具
RUN apt-get update -yq --fix-missing \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
pkg-config \
wget \
cmake \
curl \
git \
vim
# 创建一个新的Conda环境
RUN apt-get update && apt-get install -y wget \
&& wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& /bin/bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda \
&& rm Miniconda3-latest-Linux-x86_64.sh \
&& apt-get remove --purge --auto-remove -y wget \
&& apt-get clean \
&& ln -s /opt/conda/bin/conda /usr/bin/conda \
&& conda update -n base -c defaults conda
SHELL ["/bin/bash","-ic"]
# 增加cuda全局变量
RUN echo "export CUDA_HOME=/usr/local/cuda" >> ~/.bashrc \
&& echo "export PATH=${CUDA_HOME}/bin:$PATH" >> ~/.bashrc \
&& echo "export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH" >> ~/.bashrc \
&& source ~/.bashrc
#&& echo "nameserver 8.8.8.8" >> /etc/resolv.conf
# 安装cv2依赖修复libGL.so.1错误
RUN apt-get update
RUN apt-get install ffmpeg libsm6 libxext6 -y
# 配置Jupyter
ENV JUPYTER_ENABLE_LAB=yes
ENV USER=root
ENV HOME=/home/$USER
# 设置工作目录
WORKDIR /root
# 设置启动命令
CMD ["jupyter", "lab", "--ip='*'", "--port=8888", "--no-browser", "--allow-root"]

74
llm/Read.me.txt Normal file
View File

@ -0,0 +1,74 @@
一、cuda11.3容器启动过程
1、拷贝Dockerfile文件到任意磁盘目录然后执行下面的命令
docker build -t nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04-jupyter-conda .
docker images
2、启动容器
打开镜像(常规模式--支持使用GPU
docker run -i -t --gpus all nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04-jupyter-conda /bin/bash
打开镜像(增强模式--支持使用GPU、映射目录、设置内存
docker run -i -t -v /home/liguopu/:/guopu:rw --gpus all --shm-size 16G nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04 /bin/bash
测试环境(使用端口映射,把服务映射出去)
docker run -i -td --name metehuman --gpus -p 8000:8000 all nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04-jupyter-conda /bin/bash
正式使用8000端口为业务对外的服务端口根据情况可以自行增加
docker run -it --rm -p 8886:8888 -p 8000:8000 --gpus all nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04-jupyter-conda
docker run -itd -p 8886:8888 -p 8000:8000 --gpus all nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04-jupyter-conda
docker run -itd --name metehuman -p 8886:8888 -p 8000:8000 --gpus all nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04-jupyter-conda
docker run --gpus '"device=vgpu,id=0"' -it --rm nvidia/cuda:11.0-base nvidia-smi
docker run -itd --name metehuman \
-p 8885:8888 -p 8001:8000 \
-e GRANT_SUDO=yes \
-e JUPYTER_ENABLE_LAB=yes \
--user root \
--gpus all \
nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04-jupyter-conda
3、查看token
token=$(docker exec -it metehuman jupyter server list | grep -oP '(?<=token=)[a-zA-Z0-9]+')
echo $token
二、启动默认测试镜像
docker pull m11007322/cuda11.3.0-cudnn8-devel-ubuntu20.04-jupyterlab
docker run -it \
-d \
--gpus all \
-p 8887:8888 \
-p 8001:8000 \
--name metehuman2 \
--user root \
-e NB_USER="ubuntu" \
-e CHOWN_HOME=yes \
-e GRANT_SUDO=yes \
-w "/home/${NB_USER}" \
-v "$PWD":"/home/$USER/work" \
m11007322/cuda11.3.0-cudnn8-devel-ubuntu20.04-jupyterlab
三、启动jupter镜像测试
docker run -itd --name test \
-p 8886:8888 -p 8000:8000 \
-e GRANT_SUDO=yes \
-e JUPYTER_ENABLE_LAB=yes \
--user root \
--gpus '"device=vgpu,id=0"' \
nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04-jupyter-conda
docker run -it --name test --network=host --dns 8.8.8.8 --dns 8.8.4.4 --rm ubuntu
docker run -it --gpus all --network=host --rm registry.cn-hangzhou.aliyuncs.com/lipku/nerfstream:v1.3
四、查看容器IP
docker inspect bceda087524e | grep IPAddress
curl https://openai.api2d.net/v1/chat/completions \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer fk193752-RlcPi2mBQqPOU5u1F8SFkG2z0gtxD0HS' \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "你好!给我讲个笑话。"}]
}'