当前位置: 首页 > 工具软件 > dock > 使用案例 >

dockfile使用

拓拔奇
2023-12-01
# Docker image file to build and test AIMET for Tensorflow in a GPU environment

FROM nvidia/cuda:11.0.3-cudnn8-devel-ubuntu18.04

RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub

RUN apt-get update > /dev/null && \
    apt-get install --no-install-recommends -y \
        # Bare minimum Packages
        ca-certificates \
        git \
        ssh \
        sudo \
        wget \
        xterm \
        xauth > /dev/null && \
        rm -rf /var/lib/apt/lists/*

# Install certificates
RUN sudo update-ca-certificates

# Modified version of bash.bashrc that adjusts the prompt
### COPY bash.bashrc /etc/
### RUN chmod 644 /etc/bash.bashrc

### COPY profile.global /usr/local/etc/
### RUN chmod 555 /usr/local/etc/profile.global

# Add sudo support
RUN echo "%users ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers

RUN apt-get update -y > /dev/null && \
    apt-get install --no-install-recommends -y \

        # Python
        python3.6 \
        python3.6-dev \
        python3-pip \

        # lmdb dependency
        libffi-dev && \
        rm -rf /var/lib/apt/lists/*

# Python 2 pip installation
RUN apt-get update && apt-get install -y python-pip && rm -rf /var/lib/apt/lists/* && \
    python2.7 -m pip --no-cache-dir install --upgrade \
        pip==20.3.4 \
        restkit

# Upgrade Python3 pip and install some more packages
RUN python3 -m pip --no-cache-dir install --upgrade \
        pip==20.2.4 \
        'numpy<1.17,>=1.16.6' \
        setuptools==41.0.1 \
        wheel==0.33.4

ENV DEBIAN_FRONTEND=noninteractive

# Ubuntu packages for pytorch aimet
RUN dpkg --add-architecture i386
RUN apt-get update > /dev/null && \
    apt-get install --no-install-recommends -y \
        build-essential \
        emacs \
        environment-modules \
        less \
        libavcodec-dev \
        libavformat-dev \
        libgtest-dev \
        libgtk2.0-dev \
        libsox-dev \
        libsox-fmt-all \
        libstdc++6:i386 \
        libswscale-dev \
        libxtst6 \
        lsb-release \
        meld \
        nano \
        pkg-config \
        python3-tk \
        sox \
        tree \
        vim && \
        rm -rf /var/lib/apt/lists/*

# Python3 Packages
RUN python3 -m pip --no-cache-dir install \
        astroid==2.5.3 \
        attrs==19.1.0 \
        behave==1.2.6 \
        blosc==1.8.1 \
        cffi==1.12.3 \
        click \
        cython==0.29.10 \
        dataclasses \
        Deprecated \
        docutils==0.16 \
        grpcio \
        grpcio-tools \
        h5py==2.9.0 \
        ipykernel \
        Jinja2>=2.9 \
        jupyter \
        keras==2.2.4 \
        lmdb==0.95 \
        mock \
        opencv-python==4.1.0.25 \
        Pillow==8.4.0 \
        pluggy==0.12.0 \
        progressbar2 \
        psutil \
        ptflops \
        pybind11 \
        pyDOE2 \
        pylint==2.3.1 \
        pymoo==0.4.1 \
        pytest==4.6.5 \
        pytest-cov==2.6.1 \
        pytorch-ignite \
        scikit-learn \
        scipy==1.2.1 \
        sphinx==2.1.1 \
        sphinx-jinja==1.1.1 \
        sphinx-autodoc-typehints==1.6.0 \
        tensorboard==1.15 \
        tensorboardX==1.7 \
        timm==0.4.12 \
        torch==1.9.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html \
        torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html \
        torchtext==0.10.1 \
        torchvision==0.10.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html \
        tqdm \
        transformers==4.2 \
        wget && \
    python3 -m ipykernel.kernelspec

RUN cd /tmp && \
    wget https://github.com/Kitware/CMake/releases/download/v3.19.3/cmake-3.19.3-Linux-x86_64.sh && \
    mkdir /opt/cmake && \
    sh cmake-3.19.3-Linux-x86_64.sh --prefix=/opt/cmake --skip-license

RUN ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
RUN ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest
RUN ln -s /opt/cmake/bin/cpack /usr/local/bin/cpack

ENV PATH=/usr/local/bin:$PATH

# Opencv
# Ref: https://docs.opencv.org/3.1.0/d7/d9f/tutorial_linux_install.html
RUN wget -q https://github.com/Itseez/opencv/archive/3.1.0.tar.gz -O /tmp/3.1.0.tar.gz > /dev/null && \
    tar -C /tmp -xvf /tmp/3.1.0.tar.gz > /dev/null && \
    cd /tmp/opencv-3.1.0 && mkdir release && cd release && \
    cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=release -DWITH_FFMPEG=OFF -DBUILD_TESTS=OFF -DWITH_CUDA=OFF -DBUILD_PERF_TESTS=OFF -DWITH_IPP=OFF -DENABLE_PRECOMPILED_HEADERS=OFF .. > /dev/null && \
    make -j16 > /dev/null && \
    make -j16 install > /dev/null && \
    rm -rf /tmp/opencv-3.1.0*

EXPOSE 25000
RUN apt-get update && apt-get install -y openssh-server && rm -rf /var/lib/apt/lists/*
RUN mkdir /var/run/sshd

RUN apt-get update && apt-get install -y liblapacke liblapacke-dev && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y libjpeg8-dev && \
    rm -rf /var/lib/apt/lists/*

# Set up symlink to point to the correct python version
RUN ln -sf /usr/bin/python3.6 /usr/bin/python
RUN ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib

RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
    sed -i 's/Port 22/Port 25000/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

RUN python3 -m pip install git-pylint-commit-hook osqp onnx==1.8.1

# NOTE: We need to pin the holoviews version to this since the latest version has a circular dependency on bokeh 2.0.0 through the panel package
RUN python3 -m pip install holoviews==1.12.7 netron jsonschema pandas

RUN python3 -m pip install bokeh==1.2.0 hvplot==0.4.0

# Remove existing Pillow & Pillow-SIMD and replace with correct version of Pillow-SIMD.
RUN python3 -m pip uninstall -y Pillow Pillow-SIMD
RUN python3 -m pip --no-cache-dir install Pillow-SIMD==7.0.0.post3

RUN apt-get update && apt-get install -y gnupg2
RUN wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add - && echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list
RUN apt-get update --fix-missing -y && apt upgrade -y && apt-get install -y clang-11 clang-format clang-tidy-11 && \
   rm -rf /var/lib/apt/lists/*

# Create a version-less symbolic link for clang-tidy
RUN ln -s /usr/bin/run-clang-tidy-11.py /usr/bin/run-clang-tidy.py

参考文章

 类似资料: