写点什么

制作 JavaCV 应用依赖的基础 Docker 镜像 (CentOS7+JDK8+OpenCV4)

用户头像
极客good
关注
发布于: 刚刚

Default to UTF-8 file.encoding

ENV LANG C.UTF-8


RUN set -eux; \


\


arch="(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-L19

ln -sfT "$JAVA_HOME" /usr/java/default; \


ln -sfT "$JAVA_HOME" /usr/java/latest; \


for bin in "$JAVA_HOME/bin/"*; do \


base="bin")"; \


[ ! -e "/usr/bin/$base" ]; \


alternatives --install "/usr/bin/base" "$bin" 20000; \


done; \


\

basic smoke test

javac -version; \


java -version


  • 写完之后执行 docker build -t bolingcavalry/centos7.6-jdk8:0.0.1 .即可生成镜像,如果您有 hub.docker.com 的账号,还可以将其推送到中央仓库,给更多人使用

  • 用 history 命令看看镜像内容,详情如下,合计五百多兆,已经不小了:


will@Mac-mini$ docker history bolingcavalry/centos7.6-jdk8:0.0.1


IMAGE CREATED CREATED BY SIZE COMMENT


a5dead4a6505 2 days ago /bin/sh -c set -eux; 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… 202MB


  • 我这里已经推送到 hub.docker.com 上去了,执行以下命令即可下载到本地:


docker pull bolingcavalry/centos7.6-jdk8:0.0.3

[](

)CentOS7+JDK8+OpenCV4 镜像


  • 接下来可以集成 OpenCV4 了,这里有两个关键点需要注意:


  1. 受到 JavaCV 依赖的约束,OpenCV 的版本要用 4.5.3

  2. OpenCV 编译的时候要求 cmake 版本是 3.x,因此需要下载 cmake 对应版本


  • 最终,Dockerfile 内容如下,基础镜像是前面做好的 bolingcavalry/centos7.6-jdk8:0.0.1,先是安装一大堆编译所需的应用,然后下载 cmake 并安装,再下载 OpenCV-4.5.3 版本的源码然后编译,就这么简单(但其间的调试工作还是不少的,不说了,说多了都是泪):


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 \


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 \


【一线大厂Java面试题解析+核心总结学习笔记+最新架构讲解视频+实战项目源码讲义】
浏览器打开:qq.cn.hn/FTf 免费领取
复制代码


nasm \


build-essential \


ant \


unzip \


;


RUN set -eux; \


curl -fL -o cmake-3.12.2-Linux-x86_64.tar.gz https://cmake.org/files/v3.12/cmake-3.12.2-Linux-x86_64.tar.gz \


&& tar -zxvf cmake-3.12.2-Linux-x86_64.tar.gz \


&& mv cmake-3.12.2-Linux-x86_64 cmake-3.12.2 \


&& ln -sf /cmake-3.12.2/bin/* /usr/bin; \


curl -fL -o opencv-4.5.3.zip https://codeload.github.com/opencv/opencv/zip/4.5.3; \


unzip opencv-4.5.3.zip; \


rm -rf opencv-4.5.3.zip; \


cd opencv-4.5.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 install

用户头像

极客good

关注

还未添加个人签名 2021.03.18 加入

还未添加个人简介

评论

发布
暂无评论
制作JavaCV应用依赖的基础Docker镜像(CentOS7+JDK8+OpenCV4)