Docker tries to mkdir the folder that I mount

DockerDocker for-Windows

Docker Problem Overview


Why is Docker trying to create the folder that I'm mounting? If I cd to C:\Users\szx\Projects

docker run --rm -it -v "${PWD}:/src" ubuntu /bin/bash

This command exits with the following error:

C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: error while creating mount source path '/c/Users/szx/Projects': mkdir /c/Users/szx/Projects: file exists.

I'm using Docker Toolbox on Windows 10 Home.

Docker Solutions


Solution 1 - Docker

For anyone running mac/osx and encountering this, I restarted docker desktop in order to resolve this issue.

Edit: It would appear this also fixes the issue on Windows 10

Solution 2 - Docker

I got this error after changing my Windows password. I had to go into Docker settings and do "Reset credentials" under "Shared Drives", then restart Docker.

Solution 3 - Docker

My trouble was a fuse-mounted volume (e.g. sshfs, etc.) that got mounted again into the container. I didn't help that the fuse-mount had the same ownership as the user inside the container.

I assume the underlying problem is that the docker/root supervising process needs to get a hold of the fuse-mount as well when setting up the container.

Eventually it helped to mount the fuse volume with the allow_other option. Be aware that this opens access to any user. Better might be allow_root – not tested, as blocked for other reasons.

Solution 4 - Docker

Make sure the folder is being shared with the docker embedded VM. This differs with the various types of docker for desktop installs. With toolbox, I believe you can find the shared folders in the VirtualBox configuration. You should also note that these directories are case sensitive. One way to debug is to try:

docker run --rm -it -v "/:/host" ubuntu /bin/bash

And see what the filesystem looks like under "/host".

Solution 5 - Docker

I have encountered this problem on Docker (Windows) after upgrading to 2.2.0.0 (42247). The issue was with casing in the folder name that I've provided in my arguments to docker command.

Solution 6 - Docker

Did you use this container before? You could try to remove all the docker-volumes before re-executing your command.

docker volume rm `(docker volume ls -qf dangling=true)`

I tried your command locally (MacOS) without any error.

Solution 7 - Docker

I met this problem too. I used to run the following command to share the folder with container

docker run ... -v c:/seleniumplus:/dev/seleniumplus ...

But it cannot work anymore.

I am using the Windows 10 as host. My docker has recently been upgraded to "19.03.5 build 633a0e". I did change my windows password recently.

I followed the instructions to re-share the "C" drive, and restarted the docker and even restarted the computer, but it didn't work :-(. All of sudden, I found that the folder is "C:\SeleniumPlus" in the file explorer, so I ran

docker run ... -v C:/SeleniumPlus:/dev/seleniumplus ...

And it did work. So it is case-sensitive when we specify the windows shared folder in the latest docker ("19.03.5 build 633a0e").

Solution 8 - Docker

Had the exact error. In my case, I used c instead of C when changing into my directory.

Solution 9 - Docker

I solved this by restarting docker and rebuilding the images.

Solution 10 - Docker

In case you work with a separate Windows user, with which you share the volume (C: usually): you need to make sure it has access to the folders you are working with -- including their parents, up to your home directory.

Also make sure that EFS (Encrypting File System) is disabled for the shared folders.

See also my answer here.

Solution 11 - Docker

I am working in Linux (WSL2 under Windows, to be more precise) and my problem was that there existed a symlink for that folder on my host:

# docker run --rm -it -v /etc/localtime:/etc/localtime ...
docker: Error response from daemon: mkdir /etc/localtime: file exists. 


# ls -al /etc/localtime
lrwxrwxrwx 1 root root 25 May 23  2019 /etc/localtime -> ../usr/share/zoneinfo/UTC 

It worked for me to bind mount the source /usr/share/zoneinfo/UTC instead.

Solution 12 - Docker

I had the same issue when developing using docker. After I moved the project folder locally, Docker could not mount files that were listed with relatives paths, and tried to make directories instead.

Pruning docker volumes / images / containers did not solve the issue. A simple restart of docker-desktop did the job.

Solution 13 - Docker

I had this issue when I was working with Docker in a CryFS -encrypted directory in Ubuntu 20.04 LTS. The same probably happens in other UNIX-like OS-es.

The problem was that by default the CryFS-mounted virtual directory is not accessible by root, but Docker runs as root. The solution is to enable root access for FUSE-mounted volumes by editing /etc/fuse.conf: just comment out the use_allow_other setting in it. Then mount the encrypted directory with the command cryfs <secretdir> <opendir> -o allow_root (where <secretdir> and <opendir> are the encrypted directory and the FUSE mount point for the decrypted virtual directory, respectively).

Credits to the author of this comment on GitHub for calling my attention to the -o allow_root option.

Solution 14 - Docker

I have put the user_allow_other in /etc/fuse.conf. Then mounting as in the example below has solved the problem.

$ sshfs -o allow_other user@remote_server:/directory/ 

Solution 15 - Docker

I faced this error when another running container was already using folder that is being mounted in docker run command. Please check for the same & if not needed then stop the container. Best solution is to use volume by using following command -

docker volume create

then Mount this created volume if required to be used by multiple containers..

Solution 16 - Docker

For anyone having this issue in linux based os, try to remount your remote folders which are used by docker image. This helped me in ubuntu:

sudo mount -a

Solution 17 - Docker

I am running docker desktop(docker engine v20.10.5) on Windows 10 and faced similar error. I went ahead and removed the existing image from docker-desktop UI, deleted the folder in question(for me deleting the folder was an option because i was just doing some local testing), removed the existing container, restarted the docker and it worked

Solution 18 - Docker

I had this problem when the directory on my host was inside a directory mounted with gocryptfs. By default even root can't see the directory mounted by gocryptfs, only the user who executed the gocryptfs command can. To fix this add user_allow_other to /etc/fuse.conf and use the -allow_other flag e.g. gocryptfs -allow_other encrypted mnt

Solution 19 - Docker

In my case my volume path (in a .env file for docker-compose) had a space in it

/Volumes/some\ thing/folder

which did work on Docker 3 but didn't after updating to Docker 4. So I had to set my env variable to :

"/Volumes/some thing/folder"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionszxView Question on Stackoverflow
Solution 1 - DockerlancepantsView Answer on Stackoverflow
Solution 2 - DockermelicentView Answer on Stackoverflow
Solution 3 - Dockerpico_probView Answer on Stackoverflow
Solution 4 - DockerBMitchView Answer on Stackoverflow
Solution 5 - DockerVictor FView Answer on Stackoverflow
Solution 6 - DockerMornorView Answer on Stackoverflow
Solution 7 - Dockerlei wangView Answer on Stackoverflow
Solution 8 - DockerAndriiView Answer on Stackoverflow
Solution 9 - DockerKipkemoi DerekView Answer on Stackoverflow
Solution 10 - DockerTheOperatorView Answer on Stackoverflow
Solution 11 - DockerTheCooocyView Answer on Stackoverflow
Solution 12 - DockerJeppe GravgaardView Answer on Stackoverflow
Solution 13 - DockerLaryx DeciduaView Answer on Stackoverflow
Solution 14 - DockerJamesView Answer on Stackoverflow
Solution 15 - DockerAbhishek JainView Answer on Stackoverflow
Solution 16 - DockerAhmet CetinView Answer on Stackoverflow
Solution 17 - DockerJavaTecView Answer on Stackoverflow
Solution 18 - DockerkatsuView Answer on Stackoverflow
Solution 19 - DockerAlucardView Answer on Stackoverflow