导语:在构建docker image的过程中报错make /bin/sh Operation not permitted
RUN --mount=type=tmpfs,target=/tmp export PATH=/usr/local/cuda/bin:$PATH \
&& cd /tmp && wget -c http://172.16.40.245:82/pycuda-2021.1.tar.gz \
&& tar zxvf pycuda-2021.1.tar.gz \
&& cd /tmp/pycuda-2021.1 && ./configure.py --cuda-root=/usr/local/cuda --cxxflags=-std=c++11 \
&& make install \
&& find /usr/local/lib -name '*.pyc' -delete \
&& apt autoremove -y \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /root/.cache/pip/ \
&& ldconfig
docker build -t test01:pycuda .
RUN --mount=type=tmpfs,target=/tmp export PATH=/usr/local/cuda/bin:$PATH \
&& cd /tmp && wget -c http://172.16.40.245:82/pycuda-2021.1.tar.gz \
&& tar zxvf pycuda-2021.1.tar.gz \
&& apt update && apt-get install python3-dev -y \
&& cd /tmp/pycuda-2021.1 && ./configure.py --cuda-root=/usr/local/cuda --cxxflags=-std=c++11 \
&& /usr/bin/python3 setup.py install \
&& find /usr/local/lib -name '*.pyc' -delete \
&& apt autoremove -y \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /root/.cache/pip/ \
&& ldconfig
完整Dockerfile如下
### builder 先在builder中解压
#FROM ubuntu:22.04 as builder-TensorRT
#COPY TensorRT-8.0.1.6.tgz /opt/
#RUN tar zxf /opt/TensorRT-8.0.1.6.tgz -C /opt/ \
#&& rm -rf TensorRT-8.0.1.6.tgz
#FROM ubuntu:22.04 as builder-jsoncpp_dcmtk_opencv_node
#COPY jsoncpp_dcmtk_opencv_node.tgz /opt/
#RUN tar zxf /opt/jsoncpp_dcmtk_opencv_node.tgz -C /opt/ \
#&& rm -rf jsoncpp_dcmtk_opencv_node.tgz
#FROM ubuntu:22.04 as builder-freesurfer
#COPY freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.0.tgz /opt/
#RUN tar zxf /opt/freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.0.tgz -C /usr/local/ \
#&& rm -rf /opt/freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.0.tgz
### 正式构建
#FROM nvidia/cuda:11.7.0-devel-ubuntu22.04
#FROM nvidia/cuda:11.7.0-runtime-ubuntu22.04
FROM nvidia/cuda:11.7.0-base-ubuntu22.04
# 作者
MAINTAINER xujiamin
#COPY --from=builder-TensorRT /opt/TensorRT-8.0.1.6 /opt/TensorRT-8.0.1.6
COPY sources.list.ali /srv/sources.list.ali
# 先安装python3.10
RUN sed -i -e 's/^APT/# APT/' -e 's/^DPkg/# DPkg/' /etc/apt/apt.conf.d/docker-clean \
&& rm -rf /etc/apt/sources.list.d/* \
&& apt-get update \
&& apt-get install python3.10 -y --no-install-recommends \
# 安装egl
&& apt-get install libegl1-mesa-dev libgles2-mesa-dev -y --no-install-recommends \
&& rm -rf /usr/bin/python3 \
&& ln -s /usr/bin/python3.10 /usr/bin/python3 \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /root/.cache/pip/
# 安装基础命令及排查命令
RUN apt update \
&& apt-get install vim lsof git zip rsync pigz curl telnet wget unzip net-tools inetutils-ping -y --no-install-recommends \
&& apt-get install make gcc g++ -y --no-install-recommends \
# 设置时区
&& DEBIAN_FRONTEND="noninteractive" apt-get install tzdata -y --no-install-recommends \
&& rm -rf /etc/localtime \
&& ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*
# 解压编译好的openfoa7
RUN --mount=type=tmpfs,target=/tmp cd /tmp \
&& wget -c http://172.16.40.245:82/2204/openfoam7_2204.tgz \
&& tar zxvf openfoam7_2204.tgz && mv srv/OpenFOAM-7 /opt/openfoam7 && rm -rf /tmp/openfoam7_2204.tgz \
&& ldconfig
# 解压安装cudnn
RUN --mount=type=tmpfs,target=/tmp cd /tmp \
&& wget -c http://172.16.40.245:82/2204/cudnn-11.2-linux-x64-v8.1.1.33.tgz \
&& tar -xpPf /tmp/cudnn-11.2-linux-x64-v8.1.1.33.tgz -C /usr/local/ && rm -rf /tmp/cudnn-11.2-linux-x64-v8.1.1.33.tgz \
&& ldconfig
# 解压VTK
RUN --mount=type=tmpfs,target=/tmp cd /tmp \
&& wget -c http://172.16.40.245:82/VTK-8.2.0.tgz \
&& tar zxvf VTK-8.2.0.tgz && rm -rf /usr/local/include/vtk-8.2 && cp -rf VTK-8.2.0/* /usr/local/ \
&& rm -rf /srv/VTK-8.2.0 && rm -rf /tmp/VTK-8.2.0.tgz \
&& ldconfig
# 安装python依赖
RUN --mount=type=tmpfs,target=/tmp cd /tmp \
&& wget -c http://172.16.40.245:82/2204/pythonlib_drwise_2.0.tgz \
&& rm -rf /usr/lib/python* /usr/local/lib/python* \
&& tar xpPf pythonlib_drwise_2.0.tgz -C / \
&& find /usr/local/lib -name '*.pyc' -delete \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /root/.cache/pip/
COPY get-pip.py /srv/get-pip.py
# 安装pip
RUN python3 /srv/get-pip.py -i https://pypi.tuna.tsinghua.edu.cn/simple \
&& python3 -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /root/.cache/pip/
# 设置env
RUN echo "export LC_ALL='C.UTF-8'" >> /root/.bashrc \
&& echo "export LANG='C.UTF-8'" >> /root/.bashrc \
&& echo "export ANTSPATH=/usr/local/ANTs.2.1.0.Debian-Ubuntu_X64" >> /root/.bashrc \
&& echo "export DCMDICTPATH=/usr/local/share/dcmtk/dicom.dic" >>/root/.bashrc \
&& echo "export DCMDICTPATH=/usr/local/share/dcmtk/dicom.dic" >>/etc/profile \
&& echo "export CUDA_ROOT=/usr/local/cuda" >> /root/.bashrc \
&& echo "export PATH=\$PATH:\$ANTSPATH" >> /root/.bashrc \
&& echo "export LD_LIBRARY_PATH=/usr/local/lib/:\$LD_LIBRARY_PATH" >> /root/.bashrc \
#&& echo "export LD_LIBRARY_PATH=/opt/TensorRT-8.0.1.6/lib:/usr/local/lib/:\$LD_LIBRARY_PATH" >> /root/.bashrc \
&& echo "export LD_LIBRARY_PATH=/usr/local/lib/:\$LD_LIBRARY_PATH" >> /root/profile
#&& echo "export LD_LIBRARY_PATH=/opt/TensorRT-8.0.1.6/lib:/usr/local/lib/:\$LD_LIBRARY_PATH" >> /root/profile
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
ENV ANTSPATH /usr/local/ANTs.2.1.0.Debian-Ubuntu_X64
ENV DCMDICTPATH /usr/local/share/dcmtk/dicom.dic
ENV PATH $PATH:$ANTSPATH
ENV LD_LIBRARY_PATH /usr/local/lib/:$LD_LIBRARY_PATH
#ENV LD_LIBRARY_PATH /opt/TensorRT-8.0.1.6/lib:/usr/local/lib/:$LD_LIBRARY_PATH
# 这里最好根据最新的显卡版本进行更新 否则会出现cuda 804
COPY libcuda.so.525.89.02 /usr/lib/x86_64-linux-gnu/libcuda.so.525.89.02
COPY libcudadebugger.so.525.89.02 /usr/lib/x86_64-linux-gnu/libcudadebugger.so.525.89.02
RUN rm -rf /usr/lib/x86_64-linux-gnu/libcuda.so.1 \
&& ln -s /usr/lib/x86_64-linux-gnu/libcuda.so.525.89.02 /usr/lib/x86_64-linux-gnu/libcuda.so.1 \
&& ln -s /usr/lib/x86_64-linux-gnu/libcudadebugger.so.525.89.02 /usr/lib/x86_64-linux-gnu/libcudadebugger.so.1 \
&& ln -s /usr/lib/x86_64-linux-gnu/libcuda.so.1 /usr/lib/x86_64-linux-gnu/libcuda.so \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /root/.cache/pip/ \
&& ldconfig
COPY ANTs.2.1.0.Debian-Ubuntu_X64 /usr/local/ANTs.2.1.0.Debian-Ubuntu_X64
# 修改sh 到bash
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# 因gcc问题重新编译ACVD
RUN --mount=type=tmpfs,target=/tmp cd /tmp \
&& wget -c http://172.16.40.245:82/of_package.tgz \
&& wget -c http://172.16.40.245:82/of_install.sh \
&& chmod +x of_install.sh \
&& bash of_install.sh \
&& ln -sf /root/lung/CTFFR/ACVD/bin/ACVD /usr/bin/
# 安装peisu需要的算法依赖
RUN --mount=type=tmpfs,target=/tmp cd /tmp \
&& wget -c http://172.16.40.245:82/2204/peisu/lung_lib.tgz \
&& tar zxvf lung_lib.tgz \
&& cp /tmp/lib/* /lib/x86_64-linux-gnu/
RUN --mount=type=tmpfs,target=/tmp cd /tmp/ \
&& wget -c http://172.16.40.245:82/2204/cuda/cuda_debs_2204.tgz \
&& tar zxvf cuda_debs_2204.tgz \
&& cp /tmp/lib/* /usr/local/cuda/lib64/ \
&& cp -r /tmp/include /usr/local/cuda/targets/x86_64-linux/ \
#/usr/local/cuda-11.3/targets/x86_64-linux/include/cuda.h
&& cp -r /tmp/stubs /usr/local/cuda/targets/x86_64-linux/lib/ \
&& rm -rf /tmp/* \
&& ldconfig
RUN --mount=type=tmpfs,target=/tmp export PATH=/usr/local/cuda/bin:$PATH \
&& cd /tmp && wget -c http://172.16.40.245:82/pycuda-2021.1.tar.gz \
&& tar zxvf pycuda-2021.1.tar.gz \
&& apt update && apt-get install python3-dev -y \
&& cd /tmp/pycuda-2021.1 && ./configure.py --cuda-root=/usr/local/cuda --cxxflags=-std=c++11 \
&& cd /tmp/pycuda-2021.1 \
&& export CUDA_ROOT=/usr/local/cuda \
&& export NVCC=$CUDA_ROOT/bin/nvcc \
&& export CUDA_INCLUDE=$CUDA_ROOT/include \
&& export CFLAGS="-I/usr/local/cuda-11.7/targets/x86_64-linux/include" \
&& /usr/bin/python3 setup.py install \
&& find /usr/local/lib -name '*.pyc' -delete \
&& apt autoremove -y \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /root/.cache/pip/ \
&& ldconfig
# libglib2.0-dev 请务必最后安装 会造成dpkg异常
RUN apt update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install libcurand10 -y --no-install-recommends \
&& apt-get install libxrender1 -y --no-install-recommends \
&& apt-get install libglib2.0-dev -y --no-install-recommends \
# 清理hook提示
#&& echo > /etc/dpkg/dpkg.cfg.d/pkg-config-hook-config \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*
最终通过查看install的最终命令如执行python3 setup.py install
解决。