I have a Dockerfile which compiles opencv for quite a while. Recently I decided to try out buildkit (for cross compilation). However, with buildkit the opencv compilation fails. With the following error:
#9 130.0 [ 87%] Linking CXX shared library ../../lib/libopencv_imgcodecs.so
#9 130.5 [ 87%] Built target opencv_imgcodecs
#9 130.5 [ 87%] Generating src/moc_window_QT.cpp
#9 130.5 [ 87%] Generating qrc_window_QT.cpp
#9 130.5 standard input:0: Note: No relevant classes found. No output generated.
#9 130.5 RCC: Error in '/opencv/modules/highgui/src/window_QT.qrc': Cannot find file 'files_Qt/Milky/48/28.png'
#9 130.5 make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/build.make:78: modules/highgui/qrc_window_QT.cpp] Error 1
#9 130.5 make[1]: *** [CMakeFiles/Makefile2:1684: modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
#9 130.5 make: *** [Makefile:163: all] Error 2
I tried stopping the build after the git clone
to see if the file files_Qt/Milky/48/28.png
exists inside the container and it does. Moreover, if I start the compilation process from the interactive shell in the container, the compilation process succeeds.
So it seems the compilation only fails if it is part of the docker build and buildkit is enabled.
Does anybody know more details about how buildkit works and if this could have an impact on a compilation process?
The compilation command I use is:
RUN \
git clone --branch $opencv --depth 1 https://github.com/opencv/opencv.git && \
mkdir opencv/build && cd opencv/build && cmake -DBUILD_TIFF=ON \
-DCMAKE_C_COMPILER=clang-10 \
-DCMAKE_CXX_COMPILER=clang++-10 \
-DENABLE_FAST_MATH=ON \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_opencv_java=OFF \
-DWITH_CUDA=OFF \
-DENABLE_CXX11=ON \
-DWITH_OPENGL=ON \
-DWITH_OPENCL=ON \
-DWITH_IPP=ON \
-DWITH_TBB=ON \
-DWITH_EIGEN=ON \
-DWITH_V4L=OFF \
-DWITH_GTK=ON \
-DWITH_GTK_2_X=ON \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_opencv_apps=OFF \
-DBUILD_JAVA=OFF \
-DBUILD_PROTOBUF=OFF \
-DBUILD_PACKAGE=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_opencv=OFF \
-DBUILD_opencv_dnn=OFF \
-DBUILD_opencv_java_bindings_generator=OFF \
-DBUILD_opencv_shape=OFF \
-DBUILD_opencv_stitching=OFF \
-DBUILD_opencv_superres=OFF \
-DBUILD_opencv_ts=OFF \
-DBUILD_opencv_video=OFF \
-DBUILD_opencv_videoio=OFF \
-DBUILD_opencv_videostab=OFF \
-DBUILD_opencv_world=OFF \
-DBUILD_opencv_ml=OFF \
-DBUILD_opencv_photo=OFF \
-DWITH_1394=OFF \
-DWITH_FFMPEG=OFF \
-DWITH_GSTREAMER=OFF \
-DWITH_IMGCODEC_HDR=OFF \
-DWITH_IMGCODEC_PXM=OFF \
-DWITH_IMGCODEC_SUNRASTER=OFF \
-DWITH_JASPER=OFF \
-DWITH_OPENCVAMDBLAS=OFF \
-DWITH_OPENCVAMDFFT=OFF \
-DWITH_OPENEXR=OFF \
-DWITH_OPENNI=OFF \
-DWITH_OPENNI2=OFF \
-DWITH_OPENVX=OFF \
-DWITH_VTK=OFF \
-DWITH_V4L=OFF \
-DWITH_QUIRC=OFF \
-DWITH_QT=ON \
-DBUILD_opencv_calib3d=ON \
-DBUILD_opencv_core=ON \
-DBUILD_opencv_python3=ON \
-DBUILD_opencv_flann=ON \
-DBUILD_opencv_python_binding_generator=ON \
-DBUILD_opencv_highgui=ON \
-DBUILD_opencv_imgcodecs=ON \
-DBUILD_opencv_features2d=ON \
-DBUILD_opencv_imgproc=ON \
-DWITH_OPENMP=ON \
-DWITH_PNG=ON \
-DWITH_HALIDE=OFF .. && \
make -j6 && make install
rimelek
(Ćkos TakĆ”cs)
September 16, 2022, 7:07pm
2
Can you give us a working example? I mean working until the error message I tried to compile it in a container, but I should find all the dependencies that you already know and I donāt know which branch you use.
When I last checked, buildkit ran the build containers directly with runc
. Apart from that, the containers were similar. From time to time there are reports about network issues in case of buildkit in Docker Desktop, but it should not cause any ācannot find fileā issue.
Hi, here is a minimal example:
Dockerfile
FROM ubuntu:20.04
WORKDIR /
# Setup apt repositories
RUN \
apt update && \
apt install -y --no-install-recommends \
wget \
software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
apt install -y --fix-broken && \
apt update && \
apt upgrade -y && \
apt dist-upgrade -y && \
apt remove -y python3 && \
apt clean && \
apt autoremove -y && \
apt autoclean -y
# Install apt packages
# ORDER ALPHABETICALLY!
RUN \
apt install -y --no-install-recommends \
build-essential \
clang-10 \
cmake \
cpio \
git \
libdrm-dev \
libcairo2-dev \
libomp-10-dev \
llvm-10-dev \
openssh-client \
pkg-config \
python3.6-dev \
python3.6-distutils\
python3.6-minimal \
python3-pip \
qt5-default
# Install pip dependencies
# ORDER ALPHABETICALLY!
RUN python3.6 -m pip install --no-cache-dir \
numpy==1.16.1 \
setuptools==59.6.0 \
wheel==0.37.1
RUN \
ln -sf /usr/bin/python3.6 /usr/bin/python3 && \
ln -sf /usr/bin/python3 /usr/bin/python
ENV opencv=3.4.3
RUN git clone --branch $opencv --depth 1 https://github.com/opencv/opencv.git
RUN ls -al /opencv/modules/highgui/src/files_Qt/Milky/48
# build opencv from source
RUN \
mkdir opencv/build && cd opencv/build && cmake -DBUILD_TIFF=ON \
-DCMAKE_C_COMPILER=clang-10 \
-DCMAKE_CXX_COMPILER=clang++-10 \
-DENABLE_FAST_MATH=ON \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_opencv_java=OFF \
-DWITH_CUDA=OFF \
-DENABLE_CXX11=ON \
-DWITH_OPENGL=ON \
-DWITH_OPENCL=ON \
-DWITH_IPP=ON \
-DWITH_TBB=ON \
-DWITH_EIGEN=ON \
-DWITH_V4L=OFF \
-DWITH_GTK=ON \
-DWITH_GTK_2_X=ON \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_opencv_apps=OFF \
-DBUILD_JAVA=OFF \
-DBUILD_PROTOBUF=OFF \
-DBUILD_PACKAGE=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_opencv=OFF \
-DBUILD_opencv_dnn=OFF \
-DBUILD_opencv_java_bindings_generator=OFF \
-DBUILD_opencv_shape=OFF \
-DBUILD_opencv_stitching=OFF \
-DBUILD_opencv_superres=OFF \
-DBUILD_opencv_ts=OFF \
-DBUILD_opencv_video=OFF \
-DBUILD_opencv_videoio=OFF \
-DBUILD_opencv_videostab=OFF \
-DBUILD_opencv_world=OFF \
-DBUILD_opencv_ml=OFF \
-DBUILD_opencv_photo=OFF \
-DWITH_1394=OFF \
-DWITH_FFMPEG=OFF \
-DWITH_GSTREAMER=OFF \
-DWITH_IMGCODEC_HDR=OFF \
-DWITH_IMGCODEC_PXM=OFF \
-DWITH_IMGCODEC_SUNRASTER=OFF \
-DWITH_JASPER=OFF \
-DWITH_OPENCVAMDBLAS=OFF \
-DWITH_OPENCVAMDFFT=OFF \
-DWITH_OPENEXR=OFF \
-DWITH_OPENNI=OFF \
-DWITH_OPENNI2=OFF \
-DWITH_OPENVX=OFF \
-DWITH_VTK=OFF \
-DWITH_V4L=OFF \
-DWITH_QUIRC=OFF \
-DWITH_QT=ON \
-DBUILD_opencv_calib3d=ON \
-DBUILD_opencv_core=ON \
-DBUILD_opencv_python3=ON \
-DBUILD_opencv_flann=ON \
-DBUILD_opencv_python_binding_generator=ON \
-DBUILD_opencv_highgui=ON \
-DBUILD_opencv_imgcodecs=ON \
-DBUILD_opencv_features2d=ON \
-DBUILD_opencv_imgproc=ON \
-DWITH_OPENMP=ON \
-DWITH_PNG=ON \
-DWITH_HALIDE=OFF .. && \
make -j6 && make install
build command:
DOCKER_BUILDKIT=1 docker build --no-cache --progress=plain -t "buildkit_error:latest" -f Dockerfile .
rimelek
(Ćkos TakĆ”cs)
September 19, 2022, 7:19pm
4
I tried it and it finished without any error. What is your host? I tried on macOS Monterey with Docker Desktop 4.12
Iām working on Ubuntu 18.04.2 LTS (Linux 5.4.0-125-generic).
I use Docker version 19.03.3, build a872fc2f86.
Iām also working with the nvidia-docker runtime (nvidia-docker2=2.0.3+docker18.09.0-1)
rimelek
(Ćkos TakĆ”cs)
September 20, 2022, 3:49pm
6
I canāt try it on Linux with those versions, but I searched for the error message. The result was interestingā¦
result: this topic
result: your question on stackoverflow docker buildkit opencv compilation - Stack Overflow
result: Docker build fails on docker hub - OpenCV Q&A Forum
It seems they have an answer too. I quote the answer of berak
will this even run on a machine with a desktop / monitor ?
somehow your qt install looks broken, but i bet you do not need any gui at all here and could just
cmake -DBUILD_opencv_highgui=OFF
I also stumbled across that topic, unfortunately I really need the highgui option for my docker image.
I also found this thread Build docker image works local but doesn't work on docker hub - cmake - #6 by frederickzh
However, in the solution (last comment) they refer to a different post, which isnāt available anymore. The summary that was posted is unclear to me:
the issue is statx which has been updated as part of coreutils, currently if you want to build using docker hub infrastructure the only workaround is to rollback the version of coreutils package (confirmed working)
rimelek
(Ćkos TakĆ”cs)
September 23, 2022, 6:02pm
8
Sorry, I forgot to come back. I checked that repository and that was a read-only mirror. It looks like they disabled the issue tracking but you can still find that issue in the other repository:
1 Like
Thanks for that reference
While reading through the comments, I started thinking it might be due to my kernel version.
I upgraded my kernel version and now it works.
I find it strange that this can make such a difference, however, Iām happy that it is resolved.
Thanks for the support @rimelek