Problem mounting files

I’ve been having strange issues trying to mount files to me container. The error is the following:

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime creat
e failed: runc create failed: unable to start container process: error during container init: error mounting "/home/ha
jerkr/unity/fw-gears/fw-volumetrics/run.py" to rootfs at "/flywheel/v0/run.py": mount /home/hajerkr/unity/fw-gears/fw-
volumetrics/run.py:/flywheel/v0/run.py (via /proc/self/fd/7), 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 file exists on the host sysem, and clearly it’s a python file, so not a directory. I get the same issue with a config.json file as well and I am at a loss about what to do… Help would be appreciated. Thanks

Please share either the exact command used to create the container, or if docker compose was used, the content of the compose file.

I can confirm that it’s not a general problem.

Tested on:

PS C:\Users\me> wsl --version
WSL-Version: 2.3.24.0
Kernelversion: 5.15.153.1-2
WSLg-Version: 1.0.65
MSRDC-Version: 1.2.5620
Direct3D-Version: 1.611.1-81528511
DXCore-Version: 10.0.26100.1-240331-1435.ge-release
Windows-Version: 10.0.22631.4391
me@wsl-distro:~/test/wsl-file-bind$ cat <<EOF > test.sh
#!/bin/sh
echo 'this is the file bound from the host'
EOF

me@wsl-distro:~/test/wsl-file-bind$ chmod +x test.sh

me@wsl-distro:~/test/wsl-file-bind$ docker run -ti -v ./test.sh:/test.sh alpine /test.sh
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
43c4264eed91: Pull complete
Digest: sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
Status: Downloaded newer image for alpine:latest
this is the file bound from the host

My guess is that you tried to use a relative host patch, and did not start the relative path with ./, like this:

me@wsl-distro:~/test/wsl-file-bind$ docker run -ti -v test.sh:/test.sh alpine /test.sh
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/test.sh": is a directory: unknown: permission denied.

Heya thanks for getting back to me. I didn’t use a relative path, so as you can see from the error code, it prints out the path of the file I tried to mount.

Within WSL this is the command I use:

docker run -it --rm --entrypoint bash -v /home/hajerkr/unity/fw-gears/fw-volumetrics/config.json:/flywheel/v0/config.json $IMAGE

Is it not recognizing/not having access to the drive so it mounts it as a folder? I initially had my files under /mnt/c drive but I was worried about this problem happening, so I moved them to the WSL filesystem.

It still works with an absolute path:

me@wsl-distro:~/test/wsl-file-bind$ docker run -ti -v /home/me/test/wsl-file-bind/test.sh:/test.sh alpine /test.sh
this is the file bound from the host

It also works from the windows drives:

me@wsl-distro:~/test/wsl-file-bind$ cp test.sh /mnt/d/
me@wsl-distro:~/test/wsl-file-bind$ docker run -ti -v /mnt/d/test.sh:/test.sh alpine /test.sh
this is the file bound from the host

Update: I just realized that I tested it with docker-ce in WSL2. Let me spin up Docker Desktop and try again.

Something was off with my distro, so I had to use a fresh one. After enabling the WSL integration for the new distro, I repeated the tests above: same results.

I have no idea why it’s not working for you.

Please share the current error message as well if you are now testing with a new command.

You can also use

docker container inspect CONTAINERNAME

from anothet terminal or open the container in Docker Desktop and go to the Inspect tab. Search for “Mounts” and share the json block. It should explain what Docker tries to mount actually.

You can try running the command in the folder of the file you want to mount so you can rule out that you accidentally have a typo in the filepath or there is a non-printable character in the path which still have a result of trying to mount a different file.

docker run -it --rm --entrypoint bash -v $(pwd)/config.json:/flywheel/v0/config.json $IMAGE

Also try mounting the file to a different mount point in the container. If for example /flywheel or /flywheel/v0 is a file, you can’t have a mount point which has a file as part of the path of the mount point. Try for example mounting it to /testfile

Whenever that error message appeared, it was always that the user (as zhe error message says) mounted a folder onto a file or tried to mount a file to a mount point which had an existing file as part of the path o the mount point or the mount file was actually mounted onto a fodler in the container.

It could happen accidentally when you use a wrong command just once which creates a folder or file automatically and the error will persist until you remove the file or use a different path.

EDIT:

I almost forgot. If you share the image you are using or reproduce it with an image we can try, there is a better chance we can tell you what is wrong without guessing.

Thank you all for the quick responses. I am going to try and give as much information as possible from what I gathered so far trying to debug this:

  1. This problem is not inherent to just files, it’s also folder- so really mounting anything. I have read that when you try to mount a file (or folder) to the countainer and docker does not find the original file (or folder) to mount, it silently mounts it as a directory, an empty directory.
    Some evidence pertaining to this:

a. Trying to mount my run.py file (a copy of which is already in the image when building from the Dockerfile), I get the error message:

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime creat
e failed: runc create failed: unable to start container process: error during container init: error mounting "/home/ha
jerkr/unity/fw-gears/fw-volumetrics/run.py" to rootfs at "/flywheel/v0/run.py": mount /home/hajerkr/unity/fw-gears/fw-
volumetrics/run.py:/flywheel/v0/run.py (via /proc/self/fd/7), 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.

b. Trying to mount a config.json (which is not already in the image): It silently mounts it as a directory:

hajerkr@KCL54ML264:~/unity/fw-gears/fw-volumetrics$ docker run -it --rm --entrypoint bash -v /home/hajerkr/unity/fw-gears/fw-volumetrics/config.json:/flywheel/v0/config.json flywheel/volumetrics:0.0
.6
root@6f78974dda88:/flywheel/v0# ls
README.md  app  config.json  manifest.json  requirements.txt  run.py  utils
root@6f78974dda88:/flywheel/v0# ls -l
total 24
-rwxr-xr-x 1 root root 2901 Oct 22 15:49 README.md
drwxr-xr-x 2 root root 4096 Oct 22 15:49 app
drwxr-xr-x 2 root root   40 Oct 24 15:46 config.json
-rwxr-xr-x 1 root root 3360 Oct 24 15:44 manifest.json
-rwxr-xr-x 1 root root 2666 Oct 24 15:51 requirements.txt
-rwxr-xr-x 1 root root 2377 Oct 24 15:33 run.py
drwxr-xr-x 2 root root 4096 Oct 22 15:49 utils
root@6f78974dda88:/flywheel/v0#

c. Trying to mount a folder in which there is a csv file, it mounts it a folder (great), but it’s empty, meaning it probably again did not find it in the first place and silently mounted it as an empty directory with that name.

The only time I get an error message is when I try to mount a file of which a copy is already in the container, because that’s the only time it sees a clash (“are you trying to mount a file onto a directory or vice versa” … In this case it tries to mount the run.py (interpreted as a folder potentially for visibility problems described above) onto a file.

Now I have no idea why it does this. I didn’t have this issue when working from a Mac. So I feel like there might be a layer there coming between filesystems docker tries to access, wsl etc … ? But this happens as well when trying to mount from /mnt/c , hence why moved my data to my WSL filesystem.

I hope this gives more context, and I hope you don’t hit a wall like I did.

In terms of inspecting the container, this is the mount block, it’s using a relative path for some reason although I mount using the full path in my command, unsure if that’s expected / it infers the relative path or something is awry :

"Mounts": [
        {
            "Type": "volume",
            "Name": "config.json",
            "Source": "./config.json",
            "Destination": "/flywheel/v0/config.json",
            "Driver": "local",
            "Mode": "z",
            "RW": true,
            "Propagation": ""
        }
    ],

@rimelek you can find the github repo for the image here GitHub - Nialljb/fw-VoluMetrics . The config.json is something I create after so feel free to make a dummy file.
I tried your proposed solutions of mounting testfile to /testfile, nothing appears actually. When I try mounting it to /flywheel/v0, it is again an empty directory.

EDIT: For more context, my machine is SOE managed by my uni, but I have admin rights, which I needed to install Docker etc. Is it possible that this may be a rights issue? I ran the same command with sudo but it didn’t make a difference.

Thanks a lot for your help

hello,
i am experiencing a similar problem: after the latest update (Win 11 KB5044384, KB5045934) for windows, docker desktop (4.35.0 - 172550) couldn’t mount a file on a refs formatted volume. same compose file (which instructs to mounts a local config file to the container - that worked perfectly before the update) works fine on a ntfs formatted volume. can you check the volume?

Hey thanks! I’m relieved I am not alone in this. So from WSL those are not the types I see (ext4 and 9p), from WSL bash:


hajerkr@KCL54ML264:~/unity/fw-gears$ df -T .
Filesystem     Type  1K-blocks    Used Available Use% Mounted on
/dev/sde       ext4 1055762868 3785216 998274180   1% /
hajerkr@KCL54ML264:~/unity/fw-gears$ df -T ./fw-volumetrics/config.json 
Filesystem     Type  1K-blocks    Used Available Use% Mounted on
/dev/sde       ext4 1055762868 3785216 998274180   1% /
hajerkr@KCL54ML264:~/unity/fw-gears$ df -T /mnt/c/
Filesystem     Type 1K-blocks      Used Available Use% Mounted on
C:\            9p   998552572 157229220 841323352  16% /mnt/c

From powershell, my C: drive is NTFS.

With regards to docker version, I actually didn’t even install the latest update. This is happening on Current version: 4.34.3 (170107)

as far as i understand you are running docker command directly from wsl and you do have access to those files in wsl. i ran the command from windows, but apparently due to this issue wsl can’t access the refs volume containing my config files. so the copy-paste workaround may not be applicable in your case :(.

1 Like

@akurone is right that you have a different problem. First of all I don’t think you are using a dev drive but correct me if I’m wrong. The linked issue is specifically about Dev Drive.

That is weird. You use the old syntax of bind mounting files, but what you get is an actual volume with a custom source path. Single files cannot be used as volumes, so Docker somewhere created an empty folder and used a name which looks like a relative path to a file.

The mounts block you see is basically what I wrote here: https://dev.to/rimelek/everything-about-docker-volumes-1ib0#avoid-accidental-data-loss-on-volumes

Except that I wrote about it to use a custom source path of a folder, not a file.

I originally tried it on Windows 11 (the latest as far as I know except optional preview updates) and Docker Desktop 4.34 but now I updated to 4.35 and it still works perfectly for me.

Please, try this syntax which will probably not solve why you always end up with a volume instead of a bind mount, but if it works, at least you can use it until you figure out what happened.

docker run -it --rm --entrypoint bash --mount type=bind,source=/home/hajerkr/unity/fw-gears/fw-volumetrics/config.json,target=/flywheel/v0/config.json flywheel/volumetrics:0.0
.6

As you can see this syntax directly sets the type to be bind so it should not be changed to a volume. But let’s see how it works for you.

I have no idea. But if it is about rights, I would assume an error message somewhere but what you get as a volume is something I have never seen anywhere

Hey thanks a lot for this.

Re: dev drive, I am not sure what that is (now I know after a quick search), but I do not think I am using that.

I did try the syntax a couple of days ago and it was the same issue stillm config.json shows up as an empty directory.

hajerkr@KCL54ML264:~/unity/fw-gears/fw-volumetrics$ docker run -it --rm --entrypoint bash --mount type=bind,source=/home/hajerkr/unity/fw-gears/fw-volumetrics/config.json,target=/flywheel/v0/config.json flywheel/volumetrics:0.0.6
root@8a09ae83091b:/flywheel/v0# ls -l
total 24
-rwxr-xr-x 1 root root 2901 Oct 22 15:49 README.md
drwxr-xr-x 2 root root 4096 Oct 22 15:49 app
drwxr-xr-x 2 root root   40 Oct 25 12:56 config.json
-rwxr-xr-x 1 root root 3360 Oct 25 14:07 manifest.json
-rwxr-xr-x 1 root root 2666 Oct 24 15:51 requirements.txt
-rwxr-xr-x 1 root root 2377 Oct 24 15:33 run.py
drwxr-xr-x 2 root root 4096 Oct 22 15:49 utils
root@8a09ae83091b:/flywheel/v0#

In my ~/.bashrc file this is my path variable, maybe there something there … ? inconsistencies or incompatibilities? I don’t think I should if I have Docker desktop configured though, but correct me if I am wrong.

export PATH="$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin"
alias docker="docker.exe"

I even tried this from a new image from scratch, and it mounts a txt file as a folder!

Remove those lines from your bashrc or coment out the lines. Make sure WSL 2 integration is enabled in Docker Desktop.

In the meantime I will try to recreate my WSL distro as I installed Docker CE in it for a tutorial I’m working on, so maybe it works for me only because I did more than necessary.

update:

No, I have the same working bind mount with a brand new WSL distro.

1 Like

By the way with WSL integration

which docker

should return

/usr/bin/docker

and

readlink /usr/bin/docker

should return

/mnt/wsl/docker-desktop/cli-tools/usr/bin/docker

If you are using the docker.exe directly from a WSL distribution, I guess that can have unexpected results. The executable in the docker-desktop distribution is probably aware of the correct paths while Windows will not see the path in the WSL distribution. The fact that the source became a relative path is something I can’t explain, but this could be that “unexpected result”

We are on the same page

hajerkr@KCL54ML264:~/unity/fw-gears/fw-volumetrics$ which docker
/usr/local/bin/docker
hajerkr@KCL54ML264:~/unity/fw-gears/fw-volumetrics$ readlink /usr/bin/docker
/mnt/wsl/docker-desktop/cli-tools/usr/bin/docker

Rebuilt image and remounted:

"Mounts": [
        {
            "Type": "bind",
            "Source": "/home/hajerkr/unity/fw-gears/fw-volumetrics/config.json",
            "Destination": "/flywheel/v0/config.json",
            "Mode": "",
            "RW": true,
            "Propagation": "rprivate"
        }
    ],

Is it still a folder? yes :face_with_spiral_eyes: (but also I don’t know why the timestamp is older, unsure if that matters but I rebuilt with --no-cache flag)

hajerkr@KCL54ML264:~/unity/fw-gears/fw-volumetrics$ docker run -it --rm --entrypoint bash -v $(pwd)/config.json:/flywheel/v0/config.json $IMAGE
root@0a8393339cc7:/flywheel/v0# ls -l
total 24
-rwxr-xr-x 1 root root 2901 Oct 22 15:49 README.md
drwxr-xr-x 2 root root 4096 Oct 22 15:49 app
drwxr-xr-x 2 root root   40 Oct 25 14:37 config.json
-rwxr-xr-x 1 root root 3360 Oct 25 14:07 manifest.json
-rwxr-xr-x 1 root root 2666 Oct 24 15:51 requirements.txt
-rwxr-xr-x 1 root root 2377 Oct 24 15:33 run.py
drwxr-xr-x 2 root root 4096 Oct 22 15:49 utils

Please, share the output of the following commands:

docker info
docker version

Remove anything from the output you don’t want to share like IP or domain of a private registry or usename.

You could also try running:

ls -la "$(docker container inspect CONTAINERNAME --format '{{ (index .Mounts 0).Source }}')"

This uses the string from the json to list the content of the folder on the host. Replace cONTAINERNAME with the actual containername. But at this point it is also possible that even the virtual machine has the empty folder now so it will mount that instead of the one from your host.

Try this too:

docker run --rm -it --privileged --pid host ubuntu nsenter --all -t 1 -- ls -la /home

and this too, but from PowerShell, not from WSL because it mounts the WSL root from WSL

docker run --rm -it -v /:/host ubuntu ls -la /host/home
user@host:~/path/to/directory$ docker info
Client:
 Version:    27.2.0
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.16.2-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.29.2-desktop.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.34
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  desktop: Docker Desktop commands (Alpha) (Docker Inc.)
    Version:  v0.0.15
    Path:     C:\Program Files\Docker\cli-plugins\docker-desktop.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.25
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.5
    Path:     C:\Program Files\Docker\cli-plugins\docker-feedback.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.3.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.13.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 1
 Server Version: 27.2.0
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8fc6bcff51318944179630522a095cc9dbf9f353
 runc version: v1.1.13-0-g58aa920
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.153.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 22
 Total Memory: 15.35GiB
 Name: docker-desktop
 ID: REDACTED
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=npipe://\\.\pipe\docker_cli
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile


user@host:~/path/to/directory$ docker version
Client:
 Version:           27.2.0
 API version:       1.47
 Go version:        go1.21.13
 Git commit:        3ab4256
 Built:             Tue Aug 27 14:17:17 2024
 OS/Arch:           windows/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.34.3 (170107)
 Engine:
  Version:          27.2.0
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.21.13
  Git commit:       3ab5c7d
  Built:            Tue Aug 27 14:15:15 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.20
  GitCommit:        8fc6bcff51318944179630522a095cc9dbf9f353
 runc:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
user@host:~/path/to/directory$


Output:

ls -la "$(docker container inspect 03d9765cc418 --for
mat '{{ (index .Mounts 0).Source }}')"
-rw-r--r-- 1 hajerkr hajerkr 1328 Oct 24 16:43 /home/hajerkr/unity/fw-gears/fw-volumetrics/config.json

Output :

total 6
drwxr-xr-x    1 root     root          2048 Oct  2 16:42 .
drwxr-xr-x    1 root     root          4096 Oct  3 07:49 ..

Output :

Unable to find image 'ubuntu:latest' locally  
latest: Pulling from library/ubuntu                                                                                     
ff65ddf9395b: Pull complete                                                                                             
Digest: sha256:99c35190e22d294cdace2783ac55effc69d32896daaa265f0bbedbcde4fbe3e5                                         Status: Downloaded newer image for ubuntu:latest                                                                        
total 0                                                                                                                 
drwxr-xr-x 1 root root  60 Oct 25 14:37 .                                                                               
drwxr-xr-x 1 root root 220 Oct 25 14:32 ..                                                                              
drwxr-xr-x 3 root root  60 Oct 25 14:37 hajerkr 

Bonus output from PS in case needed:

wsl -l -v                                                                                           
NAME              STATE           VERSION                                                                             
* Ubuntu-20.04      Running         2                                                                                     
docker-desktop    Running         2  

Okay, so

  • the version and info output looks good.
  • ls and docker inspect shows the file is really there, but that doesn’t help now. It only shows the saved string and the path on the host is the same.
  • The first docker run command I asked you to run was actually not a good idea from me since the mount mounts the folder into the container but nsenter enters the virtual machine and lists the home folder there.
  • The second docker run command however shows that /home/hajerkr was indeed created where the docker daemon is running. So I think we have to delete it, but before we do, I recommend just renaming it in case I’m wrong so you don’t lose data. Run the following in PowerShell
docker run --rm -it -v /:/host ubuntu mv /host/home/hajekr /host/home/hajekr-backup

After that, try to mount the config file again in the WSL distribution.

I am assuming you meant

docker run --rm -it -v /:/host ubuntu mv /host/home/hajerkr /host/home/hajerkr-backup

done.

It’s not looking good doc… I tried this also from a new wsl terminal in case it needed restarting

hajerkr@KCL54ML264:~/unity/fw-gears/fw-volumetrics$ docker run --rm -it --privileged --pid host ubuntu nsenter --all -t 1 -- ls -la /home
total 6
drwxr-xr-x    1 root     root          2048 Oct  2 16:42 .
drwxr-xr-x    1 root     root          4096 Oct  3 07:49 ..
hajerkr@KCL54ML264:~/unity/fw-gears/fw-volumetrics$ docker run -it --rm --entrypoint bash -v $(pwd)/config.json:/flywheel/v0/config.json $IMAGE
root@03d9765cc418:/flywheel/v0# exit
exit
hajerkr@KCL54ML264:~/unity/fw-gears/fw-volumetrics$ docker run -it --rm --entrypoint bash -v /home/hajerkr/unity/fw-gears/fw-volumetrics/config.json:/flywheel/v0/config.json $IMAGE
root@48b0597ec7cc:/flywheel/v0# ls -l
total 24
-rwxr-xr-x 1 root root 2901 Oct 22 15:49 README.md
drwxr-xr-x 2 root root 4096 Oct 22 15:49 app
drwxr-xr-x 2 root root   40 Oct 25 15:38 config.json
-rwxr-xr-x 1 root root 3360 Oct 25 14:07 manifest.json
-rwxr-xr-x 1 root root 2666 Oct 24 15:51 requirements.txt
-rwxr-xr-x 1 root root 2377 Oct 24 15:33 run.py
drwxr-xr-x 2 root root 4096 Oct 22 15:49 utils
root@48b0597ec7cc:/flywheel/v0#

I am happy to have a live debugging session at this point :sweat_smile: