1、安装docker过程出现问题
签名无效--通过换源解决问题,把sorcere.list 中的所有都删除然后换成aliyun 的
安装docker过程会 apt-get update 出现GPG问题
我是先remove docker docker-engine docker.io containers runc 清除一下 然后update 就好了
最终docker安装成功。
2、构建docker
2.1-- “基于不同名称的Dockerfile构建镜像。”
docker build -t image_name -f Dockerfile2 .
2.2-- ”requirements.txt": not found“
构建docker过程有时候会出现 pip install -r requirements.txt 文件找不到的问题。这个时候可以通过 将requirements.txt复制到和Dockerfile同一个文件夹下,并在Dockerfile中pip install -r requirements.txt的上一行加入
COPY ./requirements.txt requirements.txt
3、docker run :
-v:挂载
譬如我要启动一个centos容器,宿主机的/test目录挂载到容器的/soft目录,可通过以下方式指定:
docker run -it -v /test:/soft centos /bin/bash。
-v 就是 把宿主机的/test目录挂载到容器的/soft目录。
-p: 端口映射:
-p 8090:80 将容器内的80端口映射到宿主机的8090,这样你就可以直接访问宿主机的8090端口看到容器内的结果了。
4、为算法配置环境镜像:
1、直接用Dockerfile 配置 (不支持交互式)
2、先拉一个基础镜像,然后run这个镜像病进入对应容器,之后在容器中进行pip 操作。(支持交互式)等环境安装之后 要docker commit将容器转换成镜像。
先docker stop 容器
执行 sudo docker commit -a "nathan" -m "create new img" eda05ad514f8 consul:v0 命令以容器为基础生成新的镜像 consul:v0,
eda05ad514f8:这个是容器的id
-a 标志作者的名字,-m表示对镜像的描述
原文链接:https://blog.csdn.net/weixin_45505313/article/details/125020076
5、DockerFile:
#nvidia/cuda:11.8.0-devel-ubuntu20.04 来自https://hub.docker.com/你只要在搜索栏搜索nvidia/cuda就有结果。
FROM nvidia/cuda:11.8.0-devel-ubuntu20.04
# 设置时区
ENV TZ=Asia/Shanghai
# 设置环境变量,避免交互式安装
ENV DEBIAN_FRONTEND=noninteractive
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone
# 设置中文
ENV LANG C.UTF-8
# 更新apt源
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list \
&& sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
# 安装编译依赖
RUN apt-get update && apt-get install -y \
fonts-wqy-microhei build-essential zlib1g-dev libncurses5-dev \
libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev \
liblzma-dev wget libsqlite3-dev tk-dev libc6-dev libbz2-dev vim \
libgl1-mesa-glx git ffmpeg && \
apt-get clean
# 下载&安装python3.10.12
RUN cd /root && \
wget https://www.python.org/ftp/python/3.10.12/Python-3.10.12.tar.xz && \
tar Jxvf Python-3.10.12.tar.xz && \
cd Python-3.10.12 && \
./configure --enable-optimizations && \
make -j "$(nproc)" && \
make altinstall && \
cd .. && rm -rf Python-3.10.12 Python-3.10.12.tar.xz
# 设置 Python 3.10 为默认 Python 版本
RUN update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 1 && \
ln -s /usr/local/bin/python3.10 /usr/bin/python && \
python -m pip install --upgrade pip
# ------------------------------------------------
# 下载安装cmake3.23
RUN wget https://cmake.org/files/v3.23/cmake-3.23.0.tar.gz && \
tar zxvf cmake-3.23.0.tar.gz && \
cd cmake-3.23.0 && \
./configure && \
make -j 8 && \
make install && \
cd .. && rm -rf cmake-3.23.0 cmake-3.23.0.tar.gz
# code & requirements
RUN cd /home && \
git clone --recursive https://ghproxy.com/https://github.com/nvlabs/tiny-cuda-nn && \
git clone https://ghproxy.com/https://github.com/qiuyu96/CoDeF.git
# ENV
ENV TCNN_CUDA_ARCHITECTURES=75
# requirements
RUN cd /home/CoDeF && \
pip install torch==2.0.0 torchvision torchaudio && \
pip install pytorch-lightning==2.0.2 && \
pip install -r requirements.txt && \
pip install commentjson && \
rm -rf /root/.cache/pip
RUN cd /home/tiny-cuda-nn && \
cmake . -B build && \
cmake --build build --config RelWithDebInfo -j && \
cd bindings/torch && \
python setup.py install
WORKDIR /home/CoDeF
6.docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].
docker 无法在run的时候使用GPU 解决办法:
sudo systemctl restart docker 重启docker 就好了