c++ - 构建 docker 镜像时 CMake 错误 : The source directory "/" does not appear to contain CMakeLists. txt

标签 c++ docker ubuntu cmake catch2

这个问题在这里已经有了答案:





Change directory command in Docker?

(5 个回答)


去年关闭。




我目前正在尝试在 Docker Image 上安装 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 上却不行。有什么我做错了。如果是这样,我该如何解决。

最佳答案

每个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

关于c++ - 构建 docker 镜像时 CMake 错误 : The source directory "/" does not appear to contain CMakeLists. txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67262942/

相关文章:

c++ - 如何在 C++ 中删除非动态分配的数组?

c++ - 在 C++ 中使用 sscanf 从字符串中提取一个 int

c++ - md5sum 包含总和本身的文件?

docker - 如何一起为docker和electronic创建安装程序?

java - 在ubuntu中从jar文件启动tomcat

c++ - QTcpClient 成功连接,但没有连接到我的服务器。它连接在哪里?

maven - 将 maven-failsafe 与 fabric8-maven 结合使用以运行命中容器化数据库的集成测试

Docker SSH 转发 - 绑定(bind) : Address not available

ubuntu - 在 Snapdragon 820 (Ubuntu 16.04) 上运行 Hexagon DSP 的 Qualcomm fastRPC 计算器示例时出错

python - pip install py-find-1st 在 ubuntu20 和 centos 上使用 python3.9 失败