"make all -j"$(nproc)" command works within Docker container but not in Dockerfile

4.1k views Asked by At

I wrote the following Dockerfile to build an image with OpenPose (https://github.com/CMU-Perceptual-Computing-Lab/openpose)

# Download base image
FROM nvidia/cuda:9.0-cudnn7-devel

# Set keyboard configuration in advance of installing CUDA
#RUN apt-get update && apt-get install -yq keyboard-configuration

#==========Caffe dependencies=================
RUN apt-get --assume-yes update && \
    apt-get --assume-yes install build-essential \
                                 libatlas-base-dev \
                                 libprotobuf-dev \
                                 libleveldb-dev \
                                 libsnappy-dev \
                                 libhdf5-serial-dev \
                                 protobuf-compiler

RUN apt-get --assume-yes install --no-install-recommends libboost-all-dev

# Remaining dependencies
RUN apt-get --assume-yes install libgflags-dev \
                                 libgoogle-glog-dev \
                                 liblmdb-dev

#=========OpenCV============
RUN apt-get update && apt-get --assume-yes install libopencv-dev \
                                                   python-opencv \
                                                   python-pip \
                                                   python-dev \
                                                   cmake \
                                                   libeigen3-dev \
                                                   doxygen

#=========Python Libs=======
RUN pip install --upgrade numpy \
                          protobuf \
                          opencv-python

#=========OpenPose==========
RUN apt-get -y install git
RUN git clone --depth 10 https://github.com/CMU-Perceptual-Computing-Lab/openpose.git /opt/openpose
RUN apt-get install -y cmake

# Set environment variables
ENV PATH "/usr/local/cuda-9.0/bin:$PATH"
ENV LD_LIBRARY_PATH "/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH"
ENV OPENPOSE_ROOT /opt/openpose

RUN cd /opt/openpose && \
    mkdir -p build && cd build && \
    cmake \
      -DCMAKE_BUILD_TYPE="Release" \
      -DBUILD_EXAMPLES=ON \
      -DBUILD_DOCS=ON \
      -DBUILD_SHARED_LIBS=ON \
      -DDOWNLOAD_BODY_25_MODEL=ON \
      -DDOWNLOAD_BODY_COCO_MODEL=ON \
      -DDOWNLOAD_BODY_MPI_MODEL=ON \
      -DDOWNLOAD_HAND_MODEL=ON \
      -DWITH_3D_RENDERER:BOOL=OFF \
      -DBUILD_PYTHON=ON ../

RUN printenv && cd opt/openpose/build && make all -n -j"$(nproc)"

When building the Dockerfile with nvidia-docker build -t openpose_image . I get the following error in the last step:

Step 14/14 : RUN printenv && cd opt/openpose/build && make all -n -j"$(nproc)"
 ---> Running in 8cbc7a731e6d
LIBRARY_PATH=/usr/local/cuda/lib64/stubs
HOSTNAME=8cbc7a731e6d
LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:/usr/local/nvidia/lib:/usr/local/nvidia/lib64
HOME=/root
CUDA_VERSION=9.0.176
NVIDIA_REQUIRE_CUDA=cuda>=9.0
NVIDIA_DRIVER_CAPABILITIES=compute,utility
PATH=/usr/local/cuda-9.0/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CUDA_PKG_VERSION=9-0=9.0.176-1
CUDNN_VERSION=7.4.1.5
PWD=/
NVIDIA_VISIBLE_DEVICES=all
NCCL_VERSION=2.3.7
OPENPOSE_ROOT=/opt/openpose
/usr/bin/cmake -H/opt/openpose -B/opt/openpose/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /opt/openpose/build/CMakeFiles /opt/openpose/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make -f CMakeFiles/doc_doxygen.dir/build.make CMakeFiles/doc_doxygen.dir/depend
make -f CMakeFiles/openpose_caffe.dir/build.make CMakeFiles/openpose_caffe.dir/depend
cd /opt/openpose/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /opt/openpose /opt/openpose /opt/openpose/build /opt/openpose/build /opt/openpose/build/CMakeFiles/doc_doxygen.dir/DependInfo.cmake --color=
make -f CMakeFiles/doc_doxygen.dir/build.make CMakeFiles/doc_doxygen.dir/build
cd /opt/openpose/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /opt/openpose /opt/openpose /opt/openpose/build /opt/openpose/build /opt/openpose/build/CMakeFiles/openpose_caffe.dir/DependInfo.cmake --color=
make -f CMakeFiles/openpose_caffe.dir/build.make CMakeFiles/openpose_caffe.dir/build
/usr/bin/cmake -E cmake_echo_color --switch= --blue --bold --progress-dir=/opt/openpose/build/CMakeFiles --progress-num=1 "Generating API documentation with Doxygen"
cd /opt/openpose/doc && /usr/bin/doxygen /opt/openpose/doc/doc_autogeneration.doxygen
/usr/bin/cmake -E cmake_echo_color --switch= --blue --bold --progress-dir=/opt/openpose/build/CMakeFiles --progress-num=4 "Creating directories for 'openpose_caffe'"
/usr/bin/cmake -E make_directory /opt/openpose/3rdparty/caffe
/usr/bin/cmake -E make_directory /opt/openpose/build/caffe/src/openpose_caffe-build
/usr/bin/cmake -E make_directory /opt/openpose/build/caffe
/usr/bin/cmake -E make_directory /opt/openpose/build/caffe/tmp
/usr/bin/cmake -E make_directory /opt/openpose/build/caffe/src/openpose_caffe-stamp
/usr/bin/cmake -E make_directory /opt/openpose/build/caffe/src
/usr/bin/cmake -E touch /opt/openpose/build/caffe/src/openpose_caffe-stamp/openpose_caffe-mkdir
/usr/bin/cmake -E cmake_echo_color --switch= --blue --bold --progress-dir=/opt/openpose/build/CMakeFiles --progress-num=5 "No download step for 'openpose_caffe'"
/usr/bin/cmake -E echo_append
/usr/bin/cmake -E touch /opt/openpose/build/caffe/src/openpose_caffe-stamp/openpose_caffe-download
/usr/bin/cmake -E cmake_echo_color --switch= --blue --bold --progress-dir=/opt/openpose/build/CMakeFiles --progress-num=7 "No patch step for 'openpose_caffe'"
/usr/bin/cmake -E echo_append
/usr/bin/cmake -E touch /opt/openpose/build/caffe/src/openpose_caffe-stamp/openpose_caffe-patch
/usr/bin/cmake -E cmake_echo_color --switch= --blue --bold --progress-dir=/opt/openpose/build/CMakeFiles --progress-num=6 "No update step for 'openpose_caffe'"
/usr/bin/cmake -E echo_append
/usr/bin/cmake -E touch /opt/openpose/build/caffe/src/openpose_caffe-stamp/openpose_caffe-update
/usr/bin/cmake -E cmake_echo_color --switch= --blue --bold --progress-dir=/opt/openpose/build/CMakeFiles --progress-num=8 "Performing configure step for 'openpose_caffe'"
cd /opt/openpose/build/caffe/src/openpose_caffe-build && /usr/bin/cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt/openpose/build/caffe -DUSE_CUDNN=ON -DCUDA_ARCH_NAME=Auto -DCPU_ONLY=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_docs=OFF -DBUILD_python=OFF -DBUILD_python_layer=OFF -DUSE_LEVELDB=OFF -DUSE_LMDB=OFF -DUSE_OPENCV=OFF "-GUnix Makefiles" /opt/openpose/3rdparty/caffe
cd /opt/openpose/build/caffe/src/openpose_caffe-build && /usr/bin/cmake -E touch /opt/openpose/build/caffe/src/openpose_caffe-stamp/openpose_caffe-configure
/usr/bin/cmake -E cmake_echo_color --switch= --blue --bold --progress-dir=/opt/openpose/build/CMakeFiles --progress-num=9 "Performing build step for 'openpose_caffe'"
cd /opt/openpose/build/caffe/src/openpose_caffe-build && make
/usr/bin/cmake -E cmake_echo_color --switch= --progress-dir=/opt/openpose/build/CMakeFiles --progress-num=1 "Built target doc_doxygen"
make[3]: *** No targets specified and no makefile found.  Stop.
CMakeFiles/openpose_caffe.dir/build.make:110: recipe for target 'caffe/src/openpose_caffe-stamp/openpose_caffe-build' failed
make[2]: *** [caffe/src/openpose_caffe-stamp/openpose_caffe-build] Error 2
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/openpose_caffe.dir/all' failed
make[1]: *** [CMakeFiles/openpose_caffe.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
The command '/bin/sh -c printenv && cd opt/openpose/build && make all -n -j"$(nproc)"' returned a non-zero code: 2

Two weird things also happen here. 1) If I run the image built so far with docker run -it openpose_image and then cd opt/openpose/build && make all -j"$(nproc)" I get the same exact error. 2) If I do instead nvidia-docker run -it openpose_image and then cd opt/openpose/build && make all -j"$(nproc)" the building runs smoothly, ending successfully without raising errors. Can somebody help me to figure out what is going on? Thanks

2

There are 2 answers

0
schrödinbug On

I assume that's because shell expansion doesn't happen with the RUN statements. I just tried using backticks instead (i.e. make -j`nproc`) and it appeared to work

0
alexm On

Shell expansion does work in RUN statements. Just remove your double quotes.

RUN printenv && cd opt/openpose/build && make all -n -j $(nproc)