【问题标题】:How do I keep the subdirectories of a directory when I bind mount it to a new docker image?将目录挂载到新的 docker 映像时,如何保留目录的子目录?
【发布时间】:2022-01-06 20:52:43
【问题描述】:

背景

我正在运行一个 docker 镜像,例如来自 facebook 的 readme:

cd docker/1.1.0/
docker build -t infer .
# mount the local examples directory inside the image
# you can mount your project directory here instead
docker run -it -v $PWD/../../examples:/infer-examples infer /bin/bash
# you should now be inside the docker container with a shell prompt, e.g.
# "root@5c3b9af90d59:/# "
cd /infer-examples/
infer -- clang -c hello.c

但是,逐字尝试示例和安装我自己的项目目录,就像它提到的那样让我一无所获。下面是我运行它时挂载我的项目目录:

在创建 infer docker 镜像时如何正确绑定挂载我的项目目录?

【问题讨论】:

  • 它说挂载你的本地示例目录。您的系统上是否有一个正在运行 docker 容器的系统?
  • 与您发布的命令中的行相比,您的命令(您发布的图像中的第一行)看起来很奇怪。里面有很多空格和'analyze-this'。
  • @HansKilian 这是一个编辑。这只是我的代码所在的另一个目录。

标签: docker mount


【解决方案1】:

您是否提取排除了根目录(下面的注释行)?这是按照说明进行的重播,没有问题:

git clone https://github.com/facebook/infer.git
cd infer/docker/1.1.0  # <--- "infer" directory required
docker build -t infer .
docker run -it -v $PWD/../../examples:/infer-examples infer /bin/bash
cd /infer-examples/
ls   
Hello.java  Hello.m  README.md  android_hello  c_hello  demo  hello.c  ios_hello  java_hello
infer -- clang -c hello.c
Capturing in make/cc mode...
Found 1 source file to analyze in /infer-examples/infer-out
1/1 [################################################################################] 100% 46.968ms

hello.c:12: error: Null Dereference
  pointer `s` last assigned on line 11 could be null and is dereferenced at line 12, column 3.
  10. void test() {
  11.   int* s = NULL;
  12.   *s = 42;
        ^
  13. }


Found 1 issue
          Issue Type(ISSUED_TYPE_ID): #
  Null Dereference(NULL_DEREFERENCE): 1

【讨论】:

  • 我还是有同样的问题。按照说明逐字执行会导致 docker 映像上出现空的 infer-examples 目录。
  • 答案中的步骤已经过测试并完全复制到这里。在目录infer/docker/1.1.0 中,当您执行ls -l $PWD/../../examples 时,您必须能够列出文件。当您的容器使用 -v $PWD/../../examples:/infer-examples 运行时,它应该会看到相同的列表。
  • 我明白了,ls -l $PWD/../../examples 完美地列出了目录。但是,使用您在评论中声明的选项运行该 docker run 命令仍然会在容器上的一个完全空的目录中重新放置。
  • 更新了截图。
猜你喜欢
  • 1970-01-01
  • 2019-02-08
  • 1970-01-01
  • 2021-06-14
  • 2016-06-10
  • 1970-01-01
  • 2019-09-27
  • 2021-08-08
  • 2021-04-25
相关资源
最近更新 更多