-
Notifications
You must be signed in to change notification settings - Fork 254
"not a directory: unknown: Are you trying to mount a directory onto a file" error produced when mounting a single file on a container #1795
Comments
Thanks for the bug report, can you tell us what |
@mat007 - after a bit more digging, the issue seems to be only in 3.4.0. In 3.4.0, when running the above service, a directory is created in place of the file. When removing the directories manually the build succeeds. I'm not sure why the folders still existed on the container after I removed the volumes and containers (I may have missed something here) Unfortunately as I no longer have 3.4.0 installed, my docker-compose version is related to the 3.3.3 which works:
|
Assuming you've been using compose v2 with Desktop 3.4.0, this issue is possibly related to 726e204 Hard to confirm with a know version and a reproductible scenario |
I'm having the same issue after updating to 3.4.0. No issue with 3.3.0 or prior. Here are some notes to reproduce the issue.
Mounting a single file actually works fine:
No error, and the file gets correctly mounted as a file inside the container ^. However, if you mount a directory AND a single file, then the issue happens:
We use this pattern for local development so we can work locally on code and have it reflect inside the container. The reason for the single file ( FWIW, I've noticed this also happens if using a different source directory on the bind mount from Side note, My workaround is to locally copy in |
I was able to reproduce this error, investigating |
I actually can also reproduce this error when using docker-compose v1
I'll try the same on my Linux box, but it looks like this is actually a Docker Desktop issue |
Confirmed this is a Docker Desktop issue, not related to docker compose:
|
Tried some variants, and it looks to be if the file mount and directory mount overlap inside the container (in your example, both are mounted to
(created "someotherfile.txt" just in case the directory wasn't synced if empty) ✅ This works (directory):
✅ This works (file):
✅ This works (file and directory, but paths do not overlap):
❌ This fails:
After running, a directory is created in
(edit: didn't clean up directory between tests) |
I still see this error with the following. Running MacOS Big Sur 11.4. Downloaded an upgraded to docker desktop 3.5.0 this morning as it mentioned fixing this bug.
My docker-compose looks like the following:
|
@sipani909 confirmed Docker Desktop issue is not fixed: $ docker run -v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa -v $(pwd)/testbed/:/root/ alpine
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/host_mnt/Users/nicolas/.ssh/id_rsa" to rootfs at "/root/.ssh/id_rsa" caused: mount through procfd: 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. |
Note that, due to the nested mounts ( |
(that is, after the issue has been fixed: those directories must be cleaned up) |
@thaJeztah IIUC mounting file into I have to admit I never tried to mix things this way :P |
Yes, that's the scenario I had in mind; in the "with bug" situation (not 100% sure, but this is the scenario I was thinking of);
In step |
@ndeloof and @thaJeztah Thanks for the detailed info! Can confirm that the issue was no longer observed after removal of line:
We will try to workaround this while the issue is looked at. |
@sipani909 check |
Hi @ndeloof checked and confirmed that it does not. However the path on our end should have been
rather than
Changed that and verified that it works with that as well. Should have caught that early on. |
Actually looking at directory contents, looks like it creates new files
|
yes it does, as explained by @thaJeztah this is required to create a mount point for the nested bind mount. Same applies if you run the equivalent |
Yes, the mount points have to be created; this is how Linux works; when you want to mount a file (or directory) somewhere, the target location must exist (to act as the "mount point"). Also see docker/compose#2957 (comment) technically it would be possible for docker to clean up those directories or files afterwards (after unmounting / when the container stops), but doing so is risky, and "complex" (docker would have to keep track if the mount point existed beforehand, or if it created it, then only remove if it created it (not in any other case). Given that bind-mounts (and volumes) can be used by multiple containers, in which case there's a risk of race-conditions (and the possibility it would be deleting files created by other containers). Because of all of those, docker (currently) won't clean up mount-points. I think I have an example written down somewhere about the mounting, let me look it up |
Found it: mkdir example && cd example
mkdir host-dir && echo hello > host-dir/some-file-on-host.txt
mkdir host-dir2 && echo hello > host-dir2/some-file-on-host2.txt
echo hello > host-file.txt
mkdir container
mkdir container/existing-dir && echo existing > container/existing-dir/existing-file.txt
tree
.
├── container
│ └── existing-dir
│ └── existing-file.txt
├── host-dir
│ └── some-file-on-host.txt
├── host-dir2
│ └── some-file-on-host2.txt
└── host-file.txt example: bind-mount a directory in the container: # bind-mounting fails if the destination doesn't exist
mount -t none -o bind host-dir container/bind-mounted-dir
mount: mounting host-dir on container/bind-mounted-dir failed: No such file or directory
# so docker creates the mountpoint (empty directory) to act as mount point
mkdir container/bind-mounted-dir
# bind-mount "host-dir" at "/bind-mounted-dir" within the container's filesystem
mount -t none -o bind host-dir container/bind-mounted-dir
# listing the content of container/bind-mounted-dir now shows the content of
# the bind-mounted directory
ls container/bind-mounted-dir
some-file-on-host.txt Note that files/directories that are mounted are the exact same files as the original files, so modifying files, or adding/removing files will modify the files in "host-dir". This would also happen if you use a "nested" mount, and a mount-point is created inside another mount: # bind-mount "host-dir2" at "/bind-mounted-dir/nested-mounted-dir" within the container's filesystem
mkdir container/bind-mounted-dir/nested-mounted-dir
mount -t none -o bind host-dir2 container/bind-mounted-dir/nested-mounted-dir
# content now shows content of "host-dir2"
ls container/bind-mounted-dir/nested-mounted-dir
some-file-on-host2.txt
# but "host-dir" was also modified, because the mount-point was created
ls host-dir
nested-mounted-dir some-file-on-host.txt Same for bind-mounting a file: # bind-mounting fails if the destination doesn't exist
mount -t none -o bind host-file.txt container/bind-mounted-file.txt
mount: mounting host-file.txt on container/bind-mounted-file.txt failed: No such file or directory
# so docker creates the mountpoint (empty file) to act as mount point
touch container/bind-mounted-file.txt
# bind-mount "host-file.txt" at "/bind-mounted-file.txt" within the container's filesystem
mount -t none -o bind host-file.txt container/bind-mounted-file.txt
# reading the content of container/bind-mounted-file.txt now shows the content
# of the bind-mounted file:
cat container/bind-mounted-file.txt
hello Note that if the destination directory already exists, bind-mounting files or directories "hide" their content: # before bind-mounting:
ls container/existing-dir
existing-file.txt
# bind-mount "host-dir" at "/bind-mounted-dir" within the container's filesystem
mount -t none -o bind host-dir container/existing-dir
# after bind-mounting, it shows the content of the bind-mounted directory:
ls container/existing-dir
nested-mounted-dir some-file-on-host.txt
# but original files are accessible again after unmounting
umount container/existing-dir
ls container/existing-dir
existing-file.txt |
if anyone ends up here due to volumes mounted from a Linux WSL instance not resolving: |
having similar issue: app:
image: invoiceninja/invoiceninja:5
container_name: InvoiceNinja5
restart: always
volumes:
- ./config/hosts:/etc/hosts:ro
- ./docker/app/public/:/var/www/app/public/:rw,delegated
- ./docker/app/storage/:/var/www/app/storage/:rw,delegated with error being:
looking in the /data/compose/8/config I see a folder called hosts being created systematically when trying to launch. Even after removing it. |
You're bind-mounting So you either need to remove that bind-mount from your compose file, or If the intent is to provide a custom |
running this: |
Basically, create the files locally before running the command fixes it since docker compose create all non existing volumes entries as directory (sometimes you need a file instead) |
Bump, is actual checked on : |
Not fully related, but got here from a different issue. might help someone I accidentally mounted a directory to a file in the container, and could no longer |
Not fully related, but got here trying to solve a different issue, might help someone I accidentally mounted a directory to a file in the container, and could no longer |
This bug is still now. |
That worked for me ! I really needed to remove the existing container with its volume before running it again, maybe something went wrong in previous runs. |
Expected behavior
I am running a service which mounts a file onto the docker container. The service is define like so in the docker-compose file:
I would expect the webpack.config.js file to mounted to the docker container.
Actual behavior
Error:
Information
I have tried a few things to try and resolve the issue:
gRPC FUSE for file sharing checkbox
off in the preferences. (there's a bunch of github issues on the docker github so I thought it might be a quick win)and
I have tried mounting the directory and that worked fine - for some reason it's failing on single files?
My colleagues (with the same docker desktop version) are running the same docker compose file to spin up their development environment without any issues. It seems like there's something specific to my machine / setup
Steps to reproduce the behavior
Please see above
The text was updated successfully, but these errors were encountered: