这个问题在这里已经有了答案:
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/