Welcome to my GitHub

Github.com/zq2599/blog…

Content: all original article classification summary and supporting source code, involving Java, Docker, Kubernetes, DevOPS, etc.;

This paper gives an overview of

  • If you have read the article “three-minute speed experience: Java version of face detection”, or even hands-on practical operation, you should be interested in the technical details behind, next please follow Chen hands-on practice together, from scratch to develop this application;
  • First, define our goals:
  1. Java version of the development of face detection applications
  2. Make the app into a Docker image
  3. Run the application in a Docker environment
  • Based on the above objectives, we can determine the following steps:
  1. Prepare the Docker base image
  2. Developing Java applications
  3. Package Java applications into package files and integrate them into the base image to obtain the final Java application image
  • The goal of this article is the first step above: getting the docker base image ready

Basic image for face detection applications

  • If you have any experience in creating Java application images, you must be wondering: as shown in the red box below, the official OpenJDK image is usually used as the base image. Why is there an article about basic mirroring?

  • For face detection applications, the official image of OpenJDK is not enough, because Java face detection needs a key technology: JavacV, in the process of JavacV need to use some local libraries of OpencV, so you need to install OpencV in the running environment

  • As shown in the figure below, a face detection application is composed of the following six parts from bottom to top. If the operating system, JDK and OpenCV at the bottom are made into basic images, it is much more convenient. When we develop applications, we only need to pay attention to the above three layers, and the above three layers are not a common Maven project?

  • By now, it should be clear what you need to do: write a Dockerfile file to create an image, which has CentOS + JDK1.8 + OpenCV

A two-step

  • I’m going to start with a CentOS + JDK image and then build an integrated OpenCV image so that I can use the CentOS + JDK1.8 image alone in some scenarios where OpenCV is not required
  • Analysis done. Let’s get started

CentOS + JDK image

  • CentOS is chosen as the operating system because it is the most commonly used in daily work

  • If you want to use CentOS as the operating system, you can use OpenJDK’s Dockerfile file to change the base image to CentOS7.6

  • Dockerfile is a file that has been downloaded and installed for different operating systems.

FROM centos:7.6.1810 RUN set-eux; \ yum install -y \ gzip \ tar \ binutils \ freetype fontconfig \ ; ENV JAVA_HOME /usr/java/openjdk-8 ENV PATH $JAVA_HOME/bin:$PATH
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8

RUN set -eux; \
    \
    arch="$(objdump="$(command -v objdump)" && objdump --file-headers "$objdump" | awk -F '[:,]+[[:space:]]+' '$1 == "architecture" { print $2 }')"; \
    case "$arch" in \
        'i386:x86-64') \
            downloadUrl='https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u292-b10/OpenJDK8U-jdk_x64_linux_8u292b10.tar.gz'; \
            ;; \
        'aarch64') \
            downloadUrl='https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u292-b10/OpenJDK8U-jdk_aarch64_linux_8u292b10.tar.gz'; \
            ;; \
        *) echo >&2 "error: unsupported architecture: '$arch'"; exit 1 ;; \
    esac; \
    \
    curl -fL -o openjdk.tgz "$downloadUrl"; \
    curl -fL -o openjdk.tgz.asc "$downloadUrl.sign"; \
    \
    export GNUPGHOME="$(mktemp -d)"; \
# pre-fetch Andrew Haley's (the OpenJDK 8 and 11 Updates OpenJDK project lead) key so we can verify that the OpenJDK key was signed by it
# (https://github.com/docker-library/openjdk/pull/322#discussion_r286839190)
# we pre-fetch this so that the signature it makes on the OpenJDK key can survive "import-clean" in gpg
    gpg --batch --keyserver keyserver.ubuntu.com --recv-keys EAC843EBD3EFDB98CC772FADA5CD6035332FA671; \
# TODO find a good link for users to verify this key is right (https://mail.openjdk.java.net/pipermail/jdk-updates-dev/2019-April/000951.html is one of the only mentions of it I can find); perhaps a note added to https://adoptopenjdk.net/upstream.html would make sense?
# no-self-sigs-only: https://salsa.debian.org/debian/gnupg2/commit/c93ca04a53569916308b369c8b218dad5ae8fe07
    gpg --batch --keyserver keyserver.ubuntu.com --keyserver-options no-self-sigs-only --recv-keys CA5F11C6CE22644D42C6AC4492EF8D39DC13168F; \
    gpg --batch --list-sigs --keyid-format 0xLONG CA5F11C6CE22644D42C6AC4492EF8D39DC13168F \
        | tee /dev/stderr \
        | grep '0xA5CD6035332FA671' \
        | grep 'Andrew Haley'; \
    gpg --batch --verify openjdk.tgz.asc openjdk.tgz; \
    rm -rf "$GNUPGHOME"; \
    \
    mkdir -p "$JAVA_HOME"; \
    tar --extract \
        --file openjdk.tgz \
        --directory "$JAVA_HOME" \
        --strip-components 1 \
        --no-same-owner \
    ; \
    rm openjdk.tgz*; \
    \
    rm -rf "$JAVA_HOME/jre/lib/security/cacerts"; \
# see "update-ca-trust" script which creates/maintains this cacerts bundle
    ln -sT /etc/pki/ca-trust/extracted/java/cacerts "$JAVA_HOME/jre/lib/security/cacerts"; \
    \
#https://github.com/oracle/docker-images/blob/a56e0d1ed968ff669d2e2ba8a1483d0f3acc80c0/OracleJava/java-8/Dockerfile#L17-L 19
    ln -sfT "$JAVA_HOME" /usr/java/default; \
    ln -sfT "$JAVA_HOME" /usr/java/latest; \
    for bin in "$JAVA_HOME/bin/"*; do \
        base="$(basename "$bin")"; \
        [ ! -e "/usr/bin/$base" ]; \
        alternatives --install "/usr/bin/$base" "$base" "$bin" 20000; \
    done; \
    \
# basic smoke test
    javac -version; \
    java -version
Copy the code
  • After writing, execute the Docker build-t BolingCavalry/Centos7.6-JDK8:0.0.1. If you have a hub.docker.com account, you can also push it to a central repository for more people to use

  • Use the history command to look at the contents of the image. The details are as follows:

CN0014009475M:~ Will $Docker history BolingCavalry/Centos7.6 - JDK8 :0.0.1 IMAGE CREATED CREATED BY SIZE COMMENT a5dead4a6505 2 days ago /bin/sh -c set -eux; The arch = "$(objdump... 209MB <missing> 2 days ago /bin/sh -c #(nop) ENV LANG=C.UTF-8 0B <missing> 2 days ago /bin/sh -c #(nop) ENV PATH = / usr/Java/openjd... 0B <missing> 2 days ago /bin/sh -c #(nop) ENV JAVA_HOME=/usr/ Java /o 0B <missing> 2 days ago /bin/sh -c set -eux; Yum install - y... 144MB <missing> 2 years ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 2 years ago /bin/sh -c #(nop) LABEL Org. Label - schema. Sc... 0B <missing> 2 years ago /bin/sh -c #(nop) ADD file:54b004357379717df... 202MBCopy the code
  • I have pushed it to hub.docker.com. You can download it locally by executing the following command:
Docker pull bolingcavalry/centos7.6 - jdk8:0.0.3Copy the code

CentOS + JDK + OpenCV image

  • The basic image is bolingCavalry/Centos7.6-JDK8:0.0.1. You install a load of applications that you need to compile, download the source code for OpencV-3.4.3, and compile. As simple as that (but during the debugging work is still a lot, do not say, say more are tears) :
FROM BolingCavalry/Centos7.6-jdk8:0.0.1 RUN echo "export LC_ALL= en_us.utF-8 ">> /etc/profile \ && source /etc/profile RUN set -eux; \ yum install -y \ make \ cmake \ gcc \ gcc-c++ \ gtk+-devel \ gimp-devel \ gimp-devel-tools \ gimp-help-browser \ zlib-devel \ libtiff-devel \ libjpeg-devel \ libpng-devel \ gstreamer-devel \ libavc1394-devel \ libraw1394-devel \ libdc1394-devel \ jasper-devel \ jasper-utils \ swig \ python \ libtool \ nasm \ build-essential \ ant \ unzip \ ; RUN set -eux; \ opencv curl - fL - o - rule 3.4.3. Zip at https://codeload.github.com/opencv/opencv/zip/3.4.3; \ unzip opencv - rule 3.4.3. Zip; \ rm - rf opencv - rule 3.4.3. Zip; Opencv \ CD - rule 3.4.3. \ mkdir build; \ cd build; \ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. ; \ make; \ make install; \ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTS=OFF .. ; \ make -j8; \ make installCopy the code
  • After you’ve written execution docker build -t bolingcavalry/opencv3.4.3:0.0.3. If you have a hub.docker.com account, you can also push it to a central repository for more people to use
  • Use the history command to look at the mirror’s contents. Here are the details. :
CN0014009475M: ~ will $docker history bolingcavalry/opencv3.4.3:0.0.3 IMAGE CREATED CREATED BY the SIZE COMMENT f0306d7a2594 2 days ago /bin/sh -c set -eux; The curl - fL - o opencv -... 2.99GB <missing> 2 days ago /bin/sh -c set-eux; Yum install - y... 638MB <missing> 2 days ago /bin/sh -c echo "export LC_ALL= en_US.utF-8 "... 638MB <missing> 2 days ago /bin/sh -c echo "export LC_ALL= en_US.utF-8 "... 1.84kB <missing> 2 days ago /bin/sh -c set-eux; The arch = "$(objdump... 209MB <missing> 2 days ago /bin/sh -c #(nop) ENV LANG=C.UTF-8 0B <missing> 2 days ago /bin/sh -c #(nop) ENV PATH = / usr/Java/openjd... 0B <missing> 2 days ago /bin/sh -c #(nop) ENV JAVA_HOME=/usr/ Java /o 0B <missing> 2 days ago /bin/sh -c set -eux; Yum install - y... 144MB <missing> 2 years ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 2 years ago /bin/sh -c #(nop) LABEL Org. Label - schema. Sc... 0B <missing> 2 years ago /bin/sh -c #(nop) ADD file:54b004357379717df... 202MBCopy the code
  • I have pushed it to hub.docker.com. You can download it locally by executing the following command:
Docker pull bolingcavalry/opencv3.4.3:0.0.3Copy the code
  • Please note that compiling opencV is very time consuming, so please make sure that the docker host is not too bad, and please wait patiently for the compilation process
  • At this point, to meet the requirements of our base image bolingcavalry/opencv3.4.3:0.0.3 has been completed, with it, let’s Java application JDK and opencv, ginny, for the next article let’s together to develop the application of the face detection;

You are not alone, Xinchen original accompany all the way

  1. Java series
  2. Spring series
  3. The Docker series
  4. Kubernetes series
  5. Database + middleware series
  6. The conversation series

Welcome to pay attention to the public number: programmer Xin Chen

Wechat search “programmer Xin Chen”, I am Xin Chen, looking forward to enjoying the Java world with you…

Github.com/zq2599/blog…