未验证 提交 87a8449a 编写于 作者: A Adam Geitgey 提交者: GitHub

Merge pull request #1284 from corbanvilla/docker-refactor

docker refactor
......@@ -394,6 +394,8 @@ to any service that supports Docker images.
You can try the Docker image locally by running: `docker-compose up --build`
There are also [several prebuilt Docker images.](docker/README.md)
Linux users with a GPU (drivers >= 384.81) and [Nvidia-Docker](https://github.com/NVIDIA/nvidia-docker) installed can run the example on the GPU: Open the [docker-compose.yml](docker-compose.yml) file and uncomment the `dockerfile: Dockerfile.gpu` and `runtime: nvidia` lines.
## Having problems?
......
FROM animcogn/face_recognition:cpu
# The rest of this file just runs an example script.
# If you wanted to use this Dockerfile to run your own app instead, maybe you would do this:
# COPY . /root/your_app_or_whatever
# RUN cd /root/your_app_or_whatever && \
# pip3 install -r requirements.txt
# RUN whatever_command_you_run_to_start_your_app
COPY . /root/face_recognition
RUN cd /root/face_recognition && \
pip3 install -r requirements.txt && \
python3 setup.py install
CMD cd /root/face_recognition/examples && \
python3 recognize_faces_in_pictures.py
# Docker Builds
If you've never used Docker before, check out the [getting started guide.](https://docs.docker.com/get-started/)
Up-to-date prebuilt images can be found [on Docker hub.](https://hub.docker.com/repository/docker/animcogn/face_recognition)
## CPU Images
- [`cpu-latest`, `cpu`, `cpu-0.1`, `latest`](cpu/Dockerfile)
- [`cpu-jupyter-kubeflow-latest`, `cpu-jupyter-kubeflow`, `cpu-jupyter-kubeflow-0.1`](cpu-jupyter-kubeflow/Dockerfile)
### GPU Images
- [`gpu-latest`, `gpu`, `gpu-0.1`](gpu/Dockerfile)
- [`gpu-jupyter-kubeflow-latest`, `gpu-jupyter-kubeflow`, `gpu-jupyter-kubeflow-0.1`](gpu-jupyter-kubeflow/Dockerfile)
The CPU images should run out of the box without any driver prerequisites.
## GPU Images
### Prerequisites
To use the GPU images, you need to have:
- [The Nvidia drivers](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#nvidia-drivers)
- [The Nvidia-docker container runtime](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#setting-up-nvidia-container-toolkit)
- [Docker configured to use the Nvidia container runtime](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html#daemon-configuration-file)
Once you have those installed, you should be ready to start running the GPU instances.
### Testing GPUs
To make sure your GPU instance is setup correctly, run the following in a container:
```python3
import dlib
print(dlib.cuda.get_num_devices())
```
## Jupyter Images
The Jupyter images are built to be deployed on [Kubeflow](https://www.kubeflow.org/). However, if you just want to run a normal Jupyter instance, they're a great template to build your own.
## Example Dockerfile
Here's an example Dockerfile using the prebuilt images:
```Dockerfile
FROM animcogn/face_recognition:gpu
COPY requirements.txt requirements.txt
RUN pip3 install -r ./requirements.txt
COPY my_app /my_app
CMD [ "python3", "/my_app/my_app.py" ]
```
FROM animcogn/face_recognition:cpu
RUN useradd -ms /bin/bash jovyan && \
chown -R jovyan:jovyan /opt/venv && \
echo 'PATH="/opt/venv/bin:$PATH"' >> /home/jovyan/.bashrc
USER jovyan
ENV PATH="/opt/venv/bin:$PATH"
RUN pip3 install jupyterlab
ENV NB_PREFIX /
CMD ["sh", "-c", "jupyter lab --notebook-dir=/home/jovyan --ip=0.0.0.0 --no-browser --allow-root --port=8888 --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_origin='*' --NotebookApp.base_url=${NB_PREFIX}"]
# Builder Image
FROM python:3.8-slim-buster AS compile
# Install Dependencies
RUN apt-get -y update && apt-get install -y --fix-missing \
build-essential \
cmake \
gfortran \
git \
wget \
curl \
graphicsmagick \
libgraphicsmagick1-dev \
libatlas-base-dev \
libavcodec-dev \
libavformat-dev \
libgtk2.0-dev \
libjpeg-dev \
liblapack-dev \
libswscale-dev \
pkg-config \
python3-dev \
python3-numpy \
software-properties-common \
zip \
&& apt-get clean && rm -rf /tmp/* /var/tmp/*
# Virtual Environment
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Install Dlib
ENV CFLAGS=-static
RUN pip3 install --upgrade pip && \
git clone -b 'v19.21' --single-branch https://github.com/davisking/dlib.git && \
cd dlib/ && \
python3 setup.py install --set BUILD_SHARED_LIBS=OFF
RUN pip3 install face_recognition
# Runtime Image
FROM python:3.8-slim-buster
COPY --from=compile /opt/venv /opt/venv
COPY --from=compile \
# Sources
/lib/x86_64-linux-gnu/libpthread.so.0 \
/lib/x86_64-linux-gnu/libz.so.1 \
/lib/x86_64-linux-gnu/libm.so.6 \
/lib/x86_64-linux-gnu/libgcc_s.so.1 \
/lib/x86_64-linux-gnu/libc.so.6 \
/lib/x86_64-linux-gnu/libdl.so.2 \
/lib/x86_64-linux-gnu/librt.so.1 \
# Destination
/lib/x86_64-linux-gnu/
COPY --from=compile \
# Sources
/usr/lib/x86_64-linux-gnu/libX11.so.6 \
/usr/lib/x86_64-linux-gnu/libXext.so.6 \
/usr/lib/x86_64-linux-gnu/libpng16.so.16 \
/usr/lib/x86_64-linux-gnu/libjpeg.so.62 \
/usr/lib/x86_64-linux-gnu/libstdc++.so.6 \
/usr/lib/x86_64-linux-gnu/libxcb.so.1 \
/usr/lib/x86_64-linux-gnu/libXau.so.6 \
/usr/lib/x86_64-linux-gnu/libXdmcp.so.6 \
/usr/lib/x86_64-linux-gnu/libbsd.so.0 \
# Destination
/usr/lib/x86_64-linux-gnu/
# Add our packages
ENV PATH="/opt/venv/bin:$PATH"
FROM animcogn/face_recognition:gpu
RUN useradd -ms /bin/bash jovyan && \
chown -R jovyan:jovyan /opt/venv && \
echo 'PATH="/opt/venv/bin:$PATH"' >> /home/jovyan/.bashrc
USER jovyan
ENV PATH="/opt/venv/bin:$PATH"
RUN pip3 install jupyterlab
ENV NB_PREFIX /
CMD ["sh", "-c", "jupyter lab --notebook-dir=/home/jovyan --ip=0.0.0.0 --no-browser --allow-root --port=8888 --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_origin='*' --NotebookApp.base_url=${NB_PREFIX}"]
FROM nvidia/cuda:11.2.0-cudnn8-devel AS compile
# Install dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get install -y \
git \
cmake \
libsm6 \
libxext6 \
libxrender-dev \
python3 \
python3-pip \
python3-venv \
python3-dev \
python3-numpy \
gcc \
build-essential \
gfortran \
wget \
curl \
graphicsmagick \
libgraphicsmagick1-dev \
libatlas-base-dev \
libavcodec-dev \
libavformat-dev \
libgtk2.0-dev \
libjpeg-dev \
liblapack-dev \
libswscale-dev \
pkg-config \
software-properties-common \
zip \
&& apt-get clean && rm -rf /tmp/* /var/tmp/*
# Virtual Environment
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Scikit learn
RUN pip3 install --upgrade pip && \
pip3 install scikit-build
# Install dlib
ENV CFLAGS=-static
RUN git clone -b 'v19.21' --single-branch https://github.com/davisking/dlib.git dlib/ && \
mkdir -p /dlib/build && \
cmake -H/dlib -B/dlib/build -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 && \
cmake --build /dlib/build && \
cd /dlib && \
python3 /dlib/setup.py install --set BUILD_SHARED_LIBS=OFF
# Install face recognition
RUN pip3 install face_recognition
# Runtime Image
FROM nvidia/cuda:11.2.0-cudnn8-runtime
# Install requirements
RUN apt-get update && apt-get install -y \
python3 \
python3-distutils
# Copy in libs
COPY --from=compile /opt/venv /opt/venv
COPY --from=compile \
# Sources
/lib/x86_64-linux-gnu/libpthread.so.0 \
/lib/x86_64-linux-gnu/libdl.so.2 \
/lib/x86_64-linux-gnu/librt.so.1 \
/lib/x86_64-linux-gnu/libX11.so.6 \
/lib/x86_64-linux-gnu/libpng16.so.16 \
/lib/x86_64-linux-gnu/libjpeg.so.8 \
/lib/x86_64-linux-gnu/libcudnn.so.8 \
/lib/x86_64-linux-gnu/libstdc++.so.6 \
/lib/x86_64-linux-gnu/libm.so.6 \
/lib/x86_64-linux-gnu/libgcc_s.so.1 \
/lib/x86_64-linux-gnu/libc.so.6 \
/lib/x86_64-linux-gnu/libxcb.so.1 \
/lib/x86_64-linux-gnu/libz.so.1 \
/lib/x86_64-linux-gnu/libXau.so.6 \
/lib/x86_64-linux-gnu/libXdmcp.so.6 \
/lib/x86_64-linux-gnu/libbsd.so.0 \
# Destination
/lib/x86_64-linux-gnu/
COPY --from=compile \
# Sources
/usr/local/cuda/lib64/libcublas.so.11 \
/usr/local/cuda/lib64/libcurand.so.10 \
/usr/local/cuda/lib64/libcusolver.so.11 \
/usr/local/cuda/lib64/libcublasLt.so.11 \
# Destination
/usr/local/cuda/lib64/
# Add our packages
ENV PATH="/opt/venv/bin:$PATH"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册