首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Docker Buildx功能-不缓存

Docker Buildx功能-不缓存
EN

Stack Overflow用户
提问于 2019-12-29 07:09:59
回答 2查看 179关注 0票数 1

我正在尝试使用buildx实验功能构建一个多拱形docker镜像。我面临的问题是,每当我执行"make“或"make install”docker时,都不会缓存该层。

我使用了不同的cmake命令,这取决于arch。

我遗漏了什么?我想要实现的是可能的吗?或者我应该只创建多个dockerfile?

代码语言:javascript
复制
FROM ubuntu:18.04 as builder

#RUN add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"

RUN set -ex && \
    apt update && apt upgrade -y && \
    apt install -y build-essential cmake pkg-config && \
    apt install -y libjpeg-dev libtiff5-dev libpng-dev && \
    apt install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev && \
    apt install -y libxvidcore-dev libx264-dev && \
    apt install -y libfontconfig1-dev libcairo2-dev && \
    apt install -y libgdk-pixbuf2.0-dev libpango1.0-dev && \
    apt install -y libgtk2.0-dev libgtk-3-dev && \
    apt install -y libatlas-base-dev gfortran && \
    apt install -y libhdf5-dev libhdf5-serial-dev && \
    apt install -y python3.7 python3.7-dev && \
    apt install -y wget unzip git

RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python get-pip.py && python3 get-pip.py
RUN rm -rf ~/.cache/pip

RUN python3 -m pip install --upgrade setuptools

RUN python3.7 get-pip.py
RUN python3.7 -m pip install --upgrade setuptools

RUN python3.7 --version
RUN python3 --version

#RUN git clone https://github.com/jasperproject/jasper-client.git jasper && \
#       chmod +x jasper/jasper.py && \
#       python3.7 -m pip install -r jasper/client/requirements.txt
#
#RUN apt install -y ash

RUN ARCH=`uname -m` && echo $ARCH

RUN /bin/bash -c 'set -xe && ARCH=`uname -m` && \
    if [ "$ARCH" == "x86_64" ]; then \
       echo "x86_64" && \
       apt-get install -y software-properties-common && \
       add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" && \
       apt update && \
       apt install -y libjasper-dev ; \
    fi'

RUN /bin/bash -c 'set -xe && ARCH=`uname -m` && \
    if [[ "$ARCH" == arm* ]]; then \
       echo "probably arm $ARCH" && \
       git clone https://github.com/jasperproject/jasper-client.git jasper && \
        chmod +x jasper/jasper.py && \
        python3.7 -m pip install -r jasper/client/requirements.txt ; \
    fi'

ARG NR_PROCS=1

ENV BUILD_FOLDER=/tmp_build/

RUN mkdir ${BUILD_FOLDER}

WORKDIR ${BUILD_FOLDER}


ADD https://github.com/opencv/opencv/archive/4.1.1.zip opencv.zip
ADD https://github.com/opencv/opencv_contrib/archive/4.1.1.zip opencv_contrib.zip


RUN set -ex && \
    unzip -qq opencv.zip && \
    unzip -qq opencv_contrib.zip && \
    mv opencv-4.1.1 opencv && \
    mv opencv_contrib-4.1.1 opencv_contrib

RUN set -ex && mkdir opencv/build && \
    echo "unzipped! ";

WORKDIR  ${BUILD_FOLDER}opencv/build

RUN python3.7 -m pip install numpy


RUN /bin/bash -c 'set -xe && ARCH=`uname -m` && \
    if [ "$ARCH" == "x86_64" ]; then \
       echo "x86_64" && \
       cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D BUILD_opencv_python3=yes \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D OPENCV_ENABLE_NONFREE=ON \
          -D CMAKE_SHARED_LINKER_FLAGS=-latomic \
          -D OPENCV_EXTRA_MODULES_PATH=${BUILD_FOLDER}opencv_contrib/modules \
          -D INSTALL_C_EXAMPLES=OFF \
          -D INSTALL_PYTHON_EXAMPLES=OFF \
          -D BUILD_EXAMPLES=OFF \
          -D PYTHON3_EXECUTABLE=$(which python3.7) \
          -D PYTHON_INCLUDE_DIR=$(python3.7 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
          -D PYTHON_INCLUDE_DIR2=$(python3.7 -c "from os.path import dirname; from distutils.sysconfig import get_config_h_filename; print(dirname(get_config_h_filename()))") \
          -D PYTHON_LIBRARY=$(python3.7 -c "from distutils.sysconfig import get_config_var;from os.path import dirname,join ; print(join(dirname(get_config_var('LIBPC')),get_config_var('LDLIBRARY')))") \
          -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python3.7 -c "import numpy; print(numpy.get_include())") \
          -D PYTHON3_PACKAGES_PATH=$(python3.7 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
          .. ; \
    fi'

RUN /bin/bash -c 'set -xe && ARCH=`uname -m` && \
    if [[ "$ARCH" == arm* ]]; then \
       echo "probably arm  $ARCH" && \
         cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D BUILD_opencv_python3=yes \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D OPENCV_ENABLE_NONFREE=ON \
          -D ENABLE_NEON=ON \
          -D ENABLE_VFPV3=ON \
          -D CMAKE_SHARED_LINKER_FLAGS=-latomic \
          -D OPENCV_EXTRA_MODULES_PATH=${BUILD_FOLDER}opencv_contrib/modules \
          -D INSTALL_C_EXAMPLES=OFF \
          -D INSTALL_PYTHON_EXAMPLES=OFF \
          -D BUILD_EXAMPLES=OFF \
          -D PYTHON3_EXECUTABLE=$(which python3.7) \
          -D PYTHON_INCLUDE_DIR=$(python3.7 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
          -D PYTHON_INCLUDE_DIR2=$(python3.7 -c "from os.path import dirname; from distutils.sysconfig import get_config_h_filename; print(dirname(get_config_h_filename()))") \
          -D PYTHON_LIBRARY=$(python3.7 -c "from distutils.sysconfig import get_config_var;from os.path import dirname,join ; print(join(dirname(get_config_var('LIBPC')),get_config_var('LDLIBRARY')))") \
          -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python3.7 -c "import numpy; print(numpy.get_include())") \
          -D PYTHON3_PACKAGES_PATH=$(python3.7 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
          .. ; \
    fi'

RUN set -xe && make -j${NR_PROCS} && make install && ldconfig

RUN python3.7 -c "import cv2; print(cv2.__version__)"

RUN apt clean

RUN rm -rf /var/lib/apt/lists/*
EN

回答 2

Stack Overflow用户

发布于 2020-03-17 20:17:49

删除作为构建器的。在多级dockerfile中使用。

票数 0
EN

Stack Overflow用户

发布于 2020-03-19 05:53:51

似乎有一个bug,很可能与moby/buildkit有关。

有关更多信息和更新,请查看https://github.com/docker/buildx/issues/206

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59515640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档