title: cmake install error: file cannot create directory. Maybe need administrative priviliges (using Dockerfile)
body: <h3>Problem</h3>
  <p>I'm trying to install OpenCV using a Dockerfile, but I keep running into one error...
  It seems that the <code>sudo make install</code> step in the Dockerfile doesn't have the right privileges, but I'm not quite sure how to solve it.</p>
  <h3>Error</h3>
  <pre><code>CMake Error at cmake_install.cmake:98 (file):
    file cannot create directory: /usr/local/lib/cmake/opencv4.  Maybe need
    administrative privileges.
  </code></pre>
  <h3>Things I tried to solve it</h3>
  <ul>
  <li>Install <code>sudo</code> package and do <code>sudo make install</code> instead of <code>make install</code></li>
  <li>Other post: <a href="https://stackoverflow.com/a/61605297/9437734">https://stackoverflow.com/a/61605297/9437734</a></li>
  </ul>
  <h3>Dockerfile</h3>
  <pre><code>FROM frolvlad/alpine-glibc:latest
  
  ARG RUNTIME_DEPS='sudo libpng libjpeg-turbo libwebp tiff jasper openexr openblas zlib'
  ARG BUILD_DEPS='wget unzip cmake build-base python3 py3-pip linux-headers libpng-dev libjpeg-turbo-dev libwebp-dev tiff-dev openexr-dev jasper-dev openblas-dev zlib-dev'
  ARG LIB_PREFIX='/usr/local'
  ARG VERSION=4.5.5
  
  ENV OPENCV_VERSION=${VERSION} \
      LIB_PREFIX=${LIB_PREFIX}
  
  RUN echo &quot;OpenCV: ${OPENCV_VERSION}&quot; \
      &amp;&amp; echo 'http://dl-cdn.alpinelinux.org/alpine/v3.10/main' &gt;&gt; /etc/apk/repositories \
      &amp;&amp; rm -rf /usr/local/lib &amp;&amp; ln -s /usr/local/lib64 /usr/local/lib \
      &amp;&amp; apk update \
      &amp;&amp; apk upgrade \
      &amp;&amp; apk add -u --no-cache $RUNTIME_DEPS \
      &amp;&amp; apk add -u --no-cache --virtual .build-dependencies $BUILD_DEPS \
      &amp;&amp; wget -q https://github.com/Itseez/opencv/archive/${OPENCV_VERSION}.zip -O opencv.zip \
      &amp;&amp; wget -q https://github.com/Itseez/opencv_contrib/archive/${OPENCV_VERSION}.zip -O opencv_contrib.zip \
      &amp;&amp; mkdir /opencv \
      &amp;&amp; mv opencv.zip opencv_contrib.zip /opencv \
      &amp;&amp; cd /opencv \
      &amp;&amp; unzip -qq opencv.zip \
      &amp;&amp; mv opencv-${OPENCV_VERSION} opencv \
      &amp;&amp; unzip -qq opencv_contrib.zip \
      &amp;&amp; mv opencv_contrib-${OPENCV_VERSION} opencv_contrib \
      &amp;&amp; mkdir opencv/build \
      &amp;&amp; cd opencv/build \
      &amp;&amp; opencv_cmake_flags=&quot;-D CMAKE_BUILD_TYPE=RELEASE \
      -D BUILD_DOCS=OFF \
      -D BUILD_TESTS=OFF \
      -D BUILD_PERF_TESTS=OFF \
      -D BUILD_JAVA=OFF \
      -D BUILD_opencv_apps=OFF \
      -D BUILD_opencv_aruco=OFF \
      -D BUILD_opencv_bgsegm=OFF \
      -D BUILD_opencv_bioinspired=OFF \
      -D BUILD_opencv_ccalib=OFF \
      -D BUILD_opencv_datasets=OFF \
      -D BUILD_opencv_dnn_objdetect=OFF \
      -D BUILD_opencv_dpm=OFF \
      -D BUILD_opencv_fuzzy=OFF \
      -D BUILD_opencv_hfs=OFF \
      -D BUILD_opencv_java_bindings_generator=OFF \
      -D BUILD_opencv_js=OFF \
      -D BUILD_opencv_img_hash=OFF \
      -D BUILD_opencv_line_descriptor=OFF \
      -D BUILD_opencv_optflow=OFF \
      -D BUILD_opencv_phase_unwrapping=OFF \
      -D BUILD_opencv_python3=OFF \
      -D BUILD_opencv_python_bindings_generator=OFF \
      -D BUILD_opencv_reg=OFF \
      -D BUILD_opencv_rgbd=OFF \
      -D BUILD_opencv_saliency=OFF \
      -D BUILD_opencv_shape=OFF \
      -D BUILD_opencv_stereo=OFF \
      -D BUILD_opencv_stitching=OFF \
      -D BUILD_opencv_structured_light=OFF \
      -D BUILD_opencv_superres=OFF \
      -D BUILD_opencv_surface_matching=OFF \
      -D BUILD_opencv_ts=OFF \
      -D BUILD_opencv_xobjdetect=OFF \
      -D BUILD_opencv_xphoto=OFF \
      -D WITH_VTK=OFF \
      -D CMAKE_INSTALL_PREFIX=$LIB_PREFIX \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules&quot; \
      &amp;&amp; cmake $opencv_cmake_flags .. \
      &amp;&amp; make -j $(getconf _NPROCESSORS_ONLN) \
      &amp;&amp; cd /opencv/opencv/build \
      &amp;&amp; sudo make install \
      &amp;&amp; cd / \
      &amp;&amp; rm -rf /opencv \
      &amp;&amp; /usr/glibc-compat/sbin/ldconfig \
      &amp;&amp; apk del .build-dependencies \
      &amp;&amp; rm -rf /var/cache/apk/* /usr/share/man /usr/local/share/man /tmp/*
  </code></pre>
  <h3>My question</h3>
  <p>How to correctly install OpenCV in Docker? Other Dockerfile setups are always welcome!</p>
  <h3>Edit</h3>
  <p>Right before the <code>sudo make install</code>, inside the Dockerfile, I tried to create the folder manually by executing <code>mkdir /usr/local/lib/cmake/opencv4</code>.</p>
  <p>The result:</p>
  <pre><code>mkdir: can't create directory '/usr/local/lib/cmake/opencv4': No such file or directory
  </code></pre>
  <p>I'm now going to replace <code>mkdir /usr/local/lib/cmake/opencv4</code> with the following command: <code>mkdir -p /usr/local/lib/cmake/opencv4</code></p>