简体   繁体   中英

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.

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 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:

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.

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).

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

This did not change anything. Still the same error.

Restarted the docker daemon and also restarted my machine

This did not change anything. Still the same error.

Reproduced the same behavior under docker

To make sure it is not a docker-compose issue, I ran the following command and got the same error:

> 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:

> 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.

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 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?

Versions:

  • My machine is an 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.

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.

I just selected my local context docker context use default and now it works as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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