Docker 镜像制作 whudee/opencv

安装 portainer-ce 管理 Docker

apt install docker.io
mkdir -p ~/portainer/data/
docker run -d --restart=always --name portainer \
    -p 9000:9000 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v ~/portainer/data:/data \
    portainer/portainer-ce:latest

为ubuntu更换安装源

因为ubuntu镜像自带的安装源为国外源,所以经常安装出错,并且速度慢,可以更换为阿里源或华为源。
阿里源:/etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

华为源:/etc/apt/sources.list

deb http://repo.huaweicloud.com/ubuntu/ bionic main restricted
deb http://repo.huaweicloud.com/ubuntu/ bionic-updates main restricted
deb http://repo.huaweicloud.com/ubuntu/ bionic universe
deb http://repo.huaweicloud.com/ubuntu/ bionic-updates universe
deb http://repo.huaweicloud.com/ubuntu/ bionic multiverse
deb http://repo.huaweicloud.com/ubuntu/ bionic-updates multiverse
deb http://repo.huaweicloud.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://repo.huaweicloud.com/ubuntu bionic-security main restricted
deb http://repo.huaweicloud.com/ubuntu bionic-security universe
deb http://repo.huaweicloud.com/ubuntu bionic-security multiverse

制做 Docker 镜像 whudee/opencv:3.4.5

Dockerfile:

FROM ubuntu:18.04
WORKDIR /root
# 把安装源换成华为或阿里的
ADD sources.list /etc/apt/
# 把临时软件包用 buildDeps 代替,方便最后打包前卸载
RUN buildDeps='wget unzip' \
    && apt-get update \
    #&& apt-get upgrage \
    && apt-get install -y $buildDeps \
    && apt-get install -y build-essential g++-8 cmake pkg-config \
    && apt-get install -y libgtk2.0-dev libopenblas-dev libboost-all-dev \
    && apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff5-dev libtiff-dev libdc1394-22-dev libx264-dev \
    #&& apt-get install -y ffmpeg \
    && wget https://github.com/opencv/opencv/archive/3.4.5.zip \
    && unzip 3.4.5.zip \
    && cd opencv-3.4.5 \
    && mkdir build \
    && cd build \
    && cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TIFF=ON -D WITH_TBB=ON .. \
    && make \
    && make install \
    && cd ../.. \
    && rm opencv-3.4.5 -rf \
    && rm 3.4.5.zip \
    && apt-get purge -y --auto-remove $buildDeps

制做 Docker 镜像 whudee/opencv:dlib (镜像最小化)

FROM ubuntu:18.04 as ubuntu_base

# todo: minimize this even more
ADD sources.list /etc/apt/
RUN apt-get update  -y &&\
    apt-get install -y --no-install-recommends \
        wget unzip \
        libopenblas-dev liblapack-dev \
        libavcodec-dev libavformat-dev libswscale-dev \
        libtbb2 libtbb-dev libjpeg-dev \
        libpng-dev libtiff-dev &&\
    rm -rf /var/lib/apt/lists/*

## ==================== Build-time dependency libs ======================
## This will build and install opencv and dlib into an additional dummy
## directory, /root/diff, so we can later copy in these artifacts,
## minimizing docker layer size
FROM ubuntu_base as cv_deps
WORKDIR /root
RUN apt-get update  -y &&\
    apt-get install -y cmake pkg-config build-essential checkinstall g++-8 &&\
    rm -rf /var/lib/apt/lists/* 

## ==================== Building Dlib ======================
RUN wget http://dlib.net/files/dlib-19.13.tar.bz2  &&\
    tar xf dlib-19.13.tar.bz2 && \
    cd /root &&\
    cd dlib-19.13 && \
    mkdir build && \
    cd build && \
    cmake -D CMAKE_BUILD_TYPE=Release .. && \
    make && \
    make install DESTDIR=/root/diff

## ==================== Building OpenCV ======================
ENV OPENCV_VERSION=4.1.0
RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip --no-check-certificate &&\
    unzip ${OPENCV_VERSION}.zip && \
    cd /root &&\
    mkdir -p opencv-${OPENCV_VERSION}/build && \
    cd opencv-${OPENCV_VERSION}/build && \
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TIFF=ON -D WITH_TBB=ON .. &&\
    make &&\
    make install DESTDIR=/root/diff

## ==================== Streamline container ===========================
## Clean up - start fresh and only copy in necessary stuff
## This shrinks the image from ~8 GB to ~1.6 GB
FROM ubuntu_base as final
LABEL maintainer="whudee <whudee@gmail.com>"

WORKDIR /root
# Copy in only necessary libraries
COPY --from=cv_deps /root/diff /

# Since we "imported" the build artifacts, we need to reconfigure ld
RUN ldconfig

制做 Docker 镜像 whudee/opencv:apache2php (从上一个镜像)

FROM whudee/opencv:dlib

# 设置不用人机交互及时区(避免安装php时询问)
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai

ADD sources.list /etc/apt/

RUN apt-get update  -y &&\
    apt-get install -y apache2 php7.2 libapache2-mod-php &&\
    apt-get clean &&\
    rm -rf /var/lib/apt/lists/*  &&\
    echo "ServerName localhost" >> /etc/apache2/apache2.conf &&\
    echo -e '#!/bin/sh\nservice apache2 start\n/bin/bash' > /root/autoexec.sh &&\
    chmod 777 /root/autoexec.sh 

EXPOSE 80
# 启动时自动运行批处理
CMD ["/bin/sh","/root/autoexec.sh"]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值