简体   繁体   English

Docker 卷无法覆盖文件:“不是目录:未知:您是否正在尝试将目录挂载到文件上(或反之亦然)?”

[英]Docker volume cannot overwrite file: "not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)?"

I have a docker-compose that should spin up an envoy proxy.我有一个docker-compose应该启动一个特使代理。

This worked fine a couple of months ago.这在几个月前工作得很好。 Today I continued working on the project and suddenly my setup stopped working.今天我继续做这个项目,突然我的设置停止工作了。 I cannot bring the docker-compose up anymore.我无法再调出 docker-compose。

> docker-compose up
Attaching to envoy-envoy-1
Error response from daemon: failed to create shim: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/home/fabi/IdeaProjects/realitycheck/server/envoy/envoy.yaml" to rootfs at "/etc/envoy/envoy.yaml": mount /home/fabi/IdeaProjects/realitycheck/server/envoy/envoy.yaml:/etc/envoy/envoy.yaml (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

The docker-compose.yaml file looks like this: docker-compose.yaml文件如下所示:

version: '3'
services:
  envoy:
    image: envoyproxy/envoy:v1.24-latest
    ports:
      - "8002:8002"
    volumes:
      - ./envoy.yaml:/etc/envoy/envoy.yaml:ro
    environment:
      ENVOY_UID: "0"
      ENVOY_GID: "0"
    network_mode: host

As you can see, I want to mount the local envoy.yaml file into /etc/envoy/envoy.yaml in the docker container.可以看到,我想将本地的envoy.yaml文件挂载到/etc/envoy/envoy.yaml容器中的/etc/envoy/envoy.yaml中。

My local directory looks like this:我的本地目录如下所示:

> ls -la
total 16
drwxr-xr-x 2 fabi fabi 4096 Jan  2 11:19 ./
drwxr-xr-x 6 fabi fabi 4096 Aug 10 14:41 ../
-rw-r--r-- 1 fabi fabi  478 Jan  2 10:54 docker-compose.yaml
-rw-r--r-- 1 fabi fabi 3722 Aug 12 15:05 envoy.yaml

For some reason, docker thinks that the file is a directory (or so it looks).出于某种原因,docker 认为该文件是一个目录(或者它看起来如此)。

What I have tried:我试过的:

Removing all images, volumes and containers and re-downloading/creating everything删除所有图像、卷和容器并重新下载/创建所有内容

As per answer to this: Are you trying to mount a directory onto a file (or vice-versa)?根据对此的回答: 您是否正在尝试将目录挂载到文件上(或反之亦然)?

This did not change anything.这并没有改变任何东西。 Still the same error.仍然是同样的错误。

Removed the ro modifier from the volume entry从卷条目中删除了ro修饰符

This did not change anything.这并没有改变任何东西。 Still the same error.仍然是同样的错误。

Restarted the docker daemon and also restarted my machine重新启动 docker 守护程序并重新启动我的机器

This did not change anything.这并没有改变任何东西。 Still the same error.仍然是同样的错误。

Reproduced the same behavior under docker docker下转载相同行为

To make sure it is not a docker-compose issue, I ran the following command and got the same error:为了确保它不是docker-compose问题,我运行了以下命令并得到了同样的错误:

> docker run --rm -e ENVOY_UID=0 -e ENVOY_GID=0 -v $(pwd)/envoy.yaml:/etc/envoy/envoy.yaml -p 8002:8002 --network=host  envoyproxy/envoy:v1.24-latest 

The same error:同样的错误:

WARNING: Published ports are discarded when using host network mode
docker: Error response from daemon: failed to create shim: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/home/fabi/IdeaProjects/realitycheck/server/envoy/envoy.yaml" to rootfs at "/etc/envoy/envoy.yaml": mount /home/fabi/IdeaProjects/realitycheck/server/envoy/envoy.yaml:/etc/envoy/envoy.yaml (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.

I looked into the container to see what it looks like in there and make sure there is actually an /etc/envoy and that there is also a file in that directory that is called envoy.yaml , which is true for both of them:我查看了容器,看看它在里面是什么样子,并确保实际上有一个/etc/envoy并且该目录中还有一个名为envoy.yaml的文件,这对它们都是如此:

> docker run --rm -e ENVOY_UID=0 -e ENVOY_GID=0  -p 8002:8002 --network=host --entrypoint "ls"  envoyproxy/envoy:v1.24-latest -la /etc/envoy

This produced:这产生了:

WARNING: Published ports are discarded when using host network mode
total 12
drwxr-xr-x 1 root root 4096 Dec  6 14:16 .
drwxr-xr-x 1 root root 4096 Jan  2 15:06 ..
-rw-r--r-- 1 root root 1817 Dec  6 14:14 envoy.yaml

That means that there is a /etc/envoy/envoy.yaml file in the container.这意味着容器中一个/etc/envoy/envoy.yaml文件。

Then I tried to mount the file under a different file name into the container, maybe there is a problem that docker cannot overwrite the file in the container .然后我尝试将不同文件名下的文件挂载到容器中,可能出现docker无法覆盖容器中文件的问题

docker run --rm -e ENVOY_UID=0 -e ENVOY_GID=0 -v $(pwd)/envoy.yaml:/etc/envoy/envoy2.yaml -p 8002:8002 --network=host --entrypoint "ls"  envoyproxy/envoy:v1.24-latest -la /etc/envoy

Which produced:哪个产生:

WARNING: Published ports are discarded when using host network mode
total 20
drwxr-xr-x 1 root root 4096 Jan  2 15:09 .
drwxr-xr-x 1 root root 4096 Jan  2 15:09 ..
-rw-r--r-- 1 root root 1817 Dec  6 14:14 envoy.yaml
drwxr-xr-x 2 root root 4096 Nov  7 21:27 envoy2.yaml

So now I was confident, that I can mount the files, and (for me) it does not look like a permission issue.所以现在我有信心,我可以挂载文件,并且(对我来说)它看起来不像是权限问题。

It looks like the error only appears when I want to mount over an existing file.看起来只有当我想挂载现有文件才会出现错误。

So my big questions is: What am I doing wrong here?所以我的大问题是:我在这里做错了什么? Why can't I any longer mount the config file into my container, when up until a couple of months ago I could do that.为什么我不能再将配置文件挂载到我的容器中,直到几个月前我还可以这样做。 Or is that a bug in docker?或者这是 docker 中的错误?

Versions:版本:

  • My machine is an Arch linux 6.1.1-arch1-1我的机器是 Arch linux 6.1.1-arch1-1
  • Docker version 20.10.22, build 3a2c30b63a
  • Docker Compose version 2.14.2

All versions are the most recent from the official arch repo.所有版本都是来自官方 arch repo 的最新版本。

I would appreciate any help!我将不胜感激任何帮助!

Okay, I found the issue.好的,我发现了问题。

It's so stupid, but I have selected a different docker context and therefore was not working on the docker on my local machine.这太愚蠢了,但我选择了不同的docker context ,因此无法在我本地机器上的 docker 上工作。

I just selected my local context docker context use default and now it works as expected.我刚刚选择了我的本地上下文docker context use default ,现在它按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM