CMake Error: The source directory "/" does not appear to contain CMakeLists.txt while building docker image

3k Views Asked by At

I'm currently trying to install a Catch2 on a Docker Image, for a project that I need to install. This is the Dockerfile that I currently have,

FROM ubuntu:20.04
ENV TZ=some/loc
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update && \
    apt-get -y install sudo

RUN adduser --disabled-password --gecos '' docker
RUN adduser docker sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER docker

RUN sudo apt-get update
RUN sudo apt-get install -y build-essential
RUN sudo apt-get install -y git
RUN sudo apt-get install -y cmake protobuf-compiler
RUN sudo apt-get install -y make

RUN cd /home/docker
RUN sudo git clone --single-branch --branch v2.x https://github.com/catchorg/Catch2.git
RUN cd Catch2
RUN sudo cmake -Bbuild -H. -DBUILD_TESTING=OFF

I know that I could have done a lot of things more efficiently, but I am new to Docker so used the RUN command generously. But now I am getting the error,

CMake Error: The source directory "/" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

There are steps after this to install Catch2, but its stopping at precisely this point. Installing Catch2 using these exact commands (cmake), on any Virtual Machine (VirtualBox) is working well, but not on Docker. Is there something that I'm doing wrong. If so how do I fix it.

1

There are 1 best solutions below

0
On

Each RUN is run in a separate process, so they do not affect each other. Run RUN related commands in a single process. Also do not create docker with so many useless empty layers - they will eat up your disc - prefer a single layer (each RUN is a separate layer).

# What is the piont of `USER docker` if you run it all under sudo .......

RUN apt-get update && \
    apt-get install -y \
         build-essential \
         git \ 
         cmake protobuf-compiler \
         make

RUN cd /home/docker  && \
    git clone --single-branch --branch v2.x 'https://github.com/catchorg/Catch2.git'  && \
    cd Catch2  && \
    cmake -Bbuild -H. -DBUILD_TESTING=OFF