-
-
Notifications
You must be signed in to change notification settings - Fork 47
Docker
We are aware that many users use Docker for their Nextcloud instances. Below are some examples and then some steps to help you quickly get started with Facerecognition using Docker. There are two variants: Debian using Apache and Alpine using PHP FPM. These are based on the two options available in https://github.com/nextcloud/docker
Use it as a guide to adapt it to your needs.
In this example we show how to install Dlib from a repository and PDlib from source, to build a Nextcloud image with Debian and Apache.
FROM nextcloud:apache
RUN apt update \
&& apt install -y wget gnupg2 unzip
# Enable repo and install dlib
RUN echo "deb https://repo.delellis.com.ar bullseye bullseye" > /etc/apt/sources.list.d/20-pdlib.list \
&& wget -qO - https://repo.delellis.com.ar/repo.gpg.key | apt-key add -
RUN apt update \
&& apt install -y libdlib-dev
# Install pdlib extension
RUN wget https://github.com/goodspb/pdlib/archive/master.zip \
&& mkdir -p /usr/src/php/ext/ \
&& unzip -d /usr/src/php/ext/ master.zip \
&& rm master.zip
RUN docker-php-ext-install pdlib-master
# Install bz2 to uncompress models
RUN apt install -y libbz2-dev
RUN docker-php-ext-install bz2
# Increase memory limits
RUN echo memory_limit=1024M > /usr/local/etc/php/conf.d/memory-limit.ini
# These last lines are just for testing the extension.. You can delete them.
RUN wget https://github.com/matiasdelellis/pdlib-min-test-suite/archive/master.zip \
&& unzip -d /tmp/ master.zip \
&& rm master.zip
RUN cd /tmp/pdlib-min-test-suite-master \
&& make
In this example we show how to install Dlib and PDlib from source to build a Nextcloud image with Debian and Apache. This other Dockerfile
uses multistage builds to first build the binaries of Dlib and then automatically copy the binaries to the final image.
#
# Use a temporary image to compile and test the libraries
#
FROM nextcloud:apache as builder
# Build and install dlib on builder
RUN apt-get update ; \
apt-get install -y build-essential wget cmake libx11-dev libopenblas-dev
ARG DLIB_BRANCH=v19.19
RUN wget -c -q https://github.com/davisking/dlib/archive/$DLIB_BRANCH.tar.gz \
&& tar xf $DLIB_BRANCH.tar.gz \
&& mv dlib-* dlib \
&& cd dlib/dlib \
&& mkdir build \
&& cd build \
&& cmake -DBUILD_SHARED_LIBS=ON --config Release .. \
&& make \
&& make install
# Build and install PDLib on builder
ARG PDLIB_BRANCH=master
RUN apt-get install unzip
RUN wget -c -q https://github.com/matiasdelellis/pdlib/archive/$PDLIB_BRANCH.zip \
&& unzip $PDLIB_BRANCH \
&& mv pdlib-* pdlib \
&& cd pdlib \
&& phpize \
&& ./configure \
&& make \
&& make install
# Enable PDlib on builder
# If necesary take the php settings folder uncommenting the next line
# RUN php -i | grep "Scan this dir for additional .ini files"
RUN echo "extension=pdlib.so" > /usr/local/etc/php/conf.d/pdlib.ini
# Install bzip2 needed to extract models
RUN apt-get install -y libbz2-dev
RUN docker-php-ext-install bz2
# Test PDlib instalation on builder
RUN apt-get install -y git
RUN git clone https://github.com/matiasdelellis/pdlib-min-test-suite.git \
&& cd pdlib-min-test-suite \
&& make
#
# If pass the tests, we are able to create the final image.
#
FROM nextcloud:apache
# Install dependencies to image
RUN apt-get update ; \
apt-get install -y libopenblas-base
# Install dlib and PDlib to image
COPY --from=builder /usr/local/lib/libdlib.so* /usr/local/lib
# If is necesary take the php extention folder (/usr/local/lib/php/extensions/no-debug-non-zts-20180731) uncommenting the next line
# RUN php -i | grep extension_dir
COPY --from=builder /usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdlib.so /usr/local/lib/php/extensions/no-debug-non-zts-20180731/
# Enable PDlib on final image
RUN echo "extension=pdlib.so" > /usr/local/etc/php/conf.d/pdlib.ini
# Increse memory limits
RUN echo memory_limit=1024M > /usr/local/etc/php/conf.d/memory-limit.ini
# Pdlib is already installed now on final image without all build dependencies.
# You could test again if everything is correct, uncommenting the next lines.
#
# RUN apt-get install -y git wget
# RUN git clone https://github.com/matiasdelellis/pdlib-min-test-suite.git \
# && cd pdlib-min-test-suite \
# && make
#
# At this point you meet all the dependencies to install the application
# You can skip this step and install the application from the application store
#
ARG FR_BRANCH=master
RUN apt-get install -y wget unzip nodejs npm
RUN wget -c -q -O facerecognition https://github.com/matiasdelellis/facerecognition/archive/$FR_BRANCH.zip \
&& unzip facerecognition \
&& mv facerecognition-* /usr/src/nextcloud/facerecognition \
&& cd /usr/src/nextcloud/facerecognition \
&& make
In this example we show how to install Dlib from a repository and PDlib using docker-php-ext-install to build a Nextcloud image with Alpine and PHP FPM (for use with Nginx).
FROM nextcloud:18-fpm-alpine
RUN apk add -X http://dl-cdn.alpinelinux.org/alpine/edge/testing dlib
RUN wget https://github.com/goodspb/pdlib/archive/master.zip \
&& mkdir -p /usr/src/php/ext/ \
&& unzip -d /usr/src/php/ext/ master.zip \
&& rm master.zip
RUN docker-php-ext-install pdlib-master
RUN apk add bzip2-dev
RUN docker-php-ext-install bz2
Build your new Nextcloud image: docker build . -t <name-of-your-container>
Now you must execute this image replacing the previous one in your commands.
You can enable it in the Nextcloud administration panel.
You must install the models as: docker exec -it -u www-data <name-of-your-container> ./occ face:setup --model MODEL_ID
Run the face recognition job with command: docker exec -it -u www-data <name-of-your-container> ./occ face:background_job -u <user> -t 900