【问题标题】:CMake Error: The source directory "/" does not appear to contain CMakeLists.txt while building docker image [duplicate]CMake 错误:在构建 docker 映像时,源目录“/”似乎不包含 CMakeLists.txt [重复]
【发布时间】:2021-07-19 14:36:52
【问题描述】:

我目前正在尝试在 Docker 映像上安装 Catch2,用于我需要安装的项目。这是我目前拥有的 Dockerfile,

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

我知道我本可以更高效地完成很多事情,但我是 Docker 新手,所以慷慨地使用了RUN 命令。但现在我得到了错误,

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.

在此之后有安装 Catch2 的步骤,但它恰好在此时停止。在任何虚拟机 (VirtualBox) 上使用这些确切的命令 (cmake) 安装 Catch2 运行良好,但在 Docker 上却不行。有什么我做错了。如果是这样,我该如何解决。

【问题讨论】:

  • 重读一些 docker 介绍。为什么你认为人们在 dockerfiles 中使用“&& \”,而不是单行 RUNs?
  • 是的,我可以让它更短,而且我可能会。但是如何解决cmake错误?我不知道为什么会这样。
  • 你认为人们为什么在 dockerfiles 中使用“&& \”,而不是单行 RUNs?不,这与矮小无关......

标签: c++ docker ubuntu cmake catch2


【解决方案1】:

每个RUN 都在单独的进程中运行,因此它们不会相互影响。在单个进程中运行RUN 相关命令。也不要用这么多无用的空层创建 docker - 它们会吃掉你的磁盘 - 更喜欢单层(每个 RUN 是一个单独的层)。

# 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

【讨论】:

  • 谢谢你,这很完美。
猜你喜欢
  • 1970-01-01
  • 2014-07-31
  • 2018-08-31
  • 1970-01-01
  • 2014-10-06
  • 2016-08-27
  • 1970-01-01
  • 2017-06-07
  • 2018-05-09
相关资源
最近更新 更多