服务器上的项目(musepose算法)环境转为镜像
直接使用dockerfile固然能够快速部署docker镜像,但是部署时可能发生报错,或者部署后发现有的包没有进行安装,就需要再次进行审查,本文提供一种能直接进入容器中调试,调试完成后直接转为镜像的方法。比较适合于工业项目转镜像的场景。
一、查看服务器环境下相关信息
了解清楚服务器下的一些信息,以备之后使用
- 查看服务器信息
uname -a
Linux 1l40s 5.15.0-116-generic #126-Ubuntu SMP Mon Jul 1 10:14:24 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
- 查看python版本信息
python
Python 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0] on linux
- 获取当前项目环境的所有python包信息
pip freeze > requirements_all.txt
二、服务器上生成环境镜像
登陆镜像仓库,搜索合适的镜像
- 登陆镜像仓库
https://hub.docker.com/
- 搜索合适镜像
- 拉取镜像
docker pull pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime
- 启动镜像
docker run -itd 372af(镜像id)
- 进入容器内部
docker exec -it bf2d04(容器id,通过docker ps查询) bash
- 在容器内部安装git
apt-get update
apt-get install git
- 拉取项目
git clone https://github.com/TMElyralab/MusePose.git
- 容器内部署项目
参考https://github.com/TMElyralab/MusePose/tree/main?tab=readme-ov-file部署方法 - 部署的容器转为镜像
# 1.容器转为镜像
docker commit bf2d04d86d63 musepose:0.1.0
# 训练 docker commit 13c3156a83a6 moore:0.1.0
# 2.挂载大文件后启动试试
docker run -itd -v /root//MusePose/pretrained_weights:/workspace/MusePose/pretrained_weights 8d9b85bd8fb2
# 训练 docker run -itd -v /root//Moore-AnimateAnyone:/workspace/Moore-AnimateAnyone 639c99b3
# 3.进入容器
docker exec -it d25a7b3d bash
# 4.测试启动代码,看是否可以进行信息启动
- 发生问题
-
- 1.内部空间不够
# 1. 查看当前磁盘使用情况
du -h --max-depth=1
# 2. 查看存储挂载和空间剩余情况
df -h #查看目前哪个是挂载的
# 3. 将大文件移动到存储挂载的上面
cp -r /root/animateanyone /scratch
# 4. 删除大文件
rm -rf /root/animateanyone
-
- 2.测试项目环境报错
Traceback (most recent call last):
File "/workspace/MusePose/pose_align.py", line 5, in <module>
import cv2
File "/opt/conda/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/opt/conda/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "/opt/conda/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
解决方案:
apt-get install libgl1
新的问题:
Traceback (most recent call last):
File "/workspace/MusePose/pose_align.py", line 5, in <module>
import cv2
File "/opt/conda/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/opt/conda/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "/opt/conda/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
解决方案:
apt-get install libglib2.0-0
三、上传镜像
- 登陆docker hub,注册账号并创建远程仓库
- 创建并将容器转为镜像上传
# 1. 登陆
(AA) (base) root@1l40s:/scratch# docker login
Log in with your Docker ID or email address to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com/ to create one.
You can log in with your password or a Personal Access Token (PAT). Using a limited-scope PAT grants better security and is required for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/
Username: lingyun92888
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
# 2. 容器转化为上传的镜像
docker commit d25a7b3d0b57 lingyun92888/pose:240804
# 3. 容器上传
docker push lingyun92888/pose:240804
# 4. 命令验证下,当然也可以直接登陆到docker hub上审查
docker inspect lingyun92888/pose:240804