Are you trying to mount a directory onto a file (or vice-versa)?

container init caused \"rootfs_linux.go:58: mounting
docker mount file
docker cannot mount file
docker-compose volumes
docker-compose cannot mount file
can a docker volume be a file
docker compose volume map single file
docker mount file as directory

I have a docker with version 17.06.0-ce. When I trying to install NGINX using docker with command:

docker run -p 80:80 -p 8080:8080 --name nginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx:latest

It shows that

docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\"/appdata/nginx/conf/nginx.conf\\" to rootfs \\"/var/lib/docker/aufs/mnt/dcea22444e9ffda114593b18fc8b574adfada06947385aedc2ac09f199188fa0\\" at \\"/var/lib/docker/aufs/mnt/dcea22444e9ffda114593b18fc8b574adfada06947385aedc2ac09f199188fa0/etc/nginx/nginx.conf\\" caused \\"not a directory\\"\"" : 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.

If do not mount the nginx.conf file, everything is okay. So, how can I mount the configuration file?

Because docker will recognize $PWD/conf/nginx.conf as a folder and not as a file. Check whether the $PWD/conf/ directory contains nginx.conf as a directory.

Test with

> cat $PWD/conf/nginx.conf 
cat: nginx.conf/: Is a directory

Otherwise, open a Docker issue. It's working fine for me with same configuration.

Are you trying to mount a directory onto a file (or vice-versa)? Check , 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' with  Description When trying to mount the file .angular-cli.json in a container. The error: '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' is thrown.

docker-compose in docker cannot mount file · Issue #3180 · docker , caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists  Stack Overflow Public questions and Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected

Remove the volumes associated with the container. Find the container name using docker ps -a then remove the container using:

docker rm -v <container_name>

Problem:

The error you are facing might occur if you tried running docker run command previously when file was not present at the location where it should have been in host directory. In this case docker daemon would have created a directory inside container in its place. Which later fails to map to proper file when correct files are put in host directory and docker is run again.

Solution:

Remove the volumes that are associated to the container. If you are not concerned about other container volumes, you can also use:

docker volume rm $(docker volume ls -q)

Can't seem to mount file - Open Source Registry, 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 ERROR:​  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 Seems to indicate the ./mysql/my.cnf was either not found, or the local disk was not shared with the VM in which the docker daemon runs.

Answer for people using Docker Toolbox

There have been at least 3 answers here touching on the problem, but not explaining it properly and not giving a full solution. This is just a folder mounting problem.

Description of the problem:

Docker Toolbox bypasses the Hyper-V requirement of Docker by creating a virtual machine (in VirtualBox, which comes bundled). Docker is installed and ran inside the VM. In order for Docker to function properly, it needs to have access to the from the host machine. Which here it doesn't.

After I installed Docker Toolbox it created the VirtualBox VM and only mounted C:\Users to the machine, as \c\Users\. My project was in C:\projects so nowhere on the mounted volume. When I was sending the path to the VM, it would not exist, as C:\projects isn't mounted. Hence, the error above.

Let's say I had my project containing my ngnix config in C:/projects/project_name/

Fixing it:

  1. Go to VirtualBox, right click on Default (the VM from Docker) > Settings > Shared Folders

  2. Clicking the small icon with the plus on the right side, Add a new share. I used the following settings:

  1. The above will map C:\projects to /projects (ROOT/projects) in the VM, meaning that now you can reference any path in projects like this: /projects/project_name - because project_name from C:\projects\project_name is now mounted.

To use relative paths, please consider naming the path c/projects not projects

  1. Restart everything and it should now work properly. I manually stopped the virtual machine in VirtualBox and restarted the Docker Toolbox CLI.

In my docker file, I now reference the nginx.conf like this:

volumes:
    - /projects/project_name/docker_config/nginx/nginx.conf:/etc/nginx/conf.d/default.conf

Where nginx.conf actually resides in C:\projects\project_name\docker_config\nginx\nginx.conf

How can I fix the error mounting caused "not a directory" when using , 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. ERROR: for  : 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" 👍 16 😄 1 🎉 2 ️ 3

I had the same problem. I was using Docker Desktop with WSL in Windows 10 17.09.

Cause of the problem: The problem is that Docker for Windows expects you to supply your volume paths in a format that matches this: /c/Users/username/app. But, WSL instead uses the /mnt/c/Users/username/app format. This is confusing because when checking the file in the console I saw it and for me everything was correct. I wasn't aware of the Docker for Windows expectations about the volume paths.

Solution of the problem: I binded the custom mount points to fix Docker for Windows and WSL differences: sudo mount --bind /mnt/c /c like suggested in this amazing guide Setting Up Docker for Windows and WSL to Work Flawlessly and everything is working perfectly now.

Before I start using WSL I was using Git Bash and I had this problem as well.

How to mount a config file from host to container?, 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. Warning BackOff  Unable to mount a file with docker-compose Are you trying to mount a directory onto a file (or vice-versa)? i wasted so many hours trying to solve this. Your

Docker, caused \“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  First, you must create a directory to use as a mount point for the file Once the mount point is created, you can mount the file system (by using the mountcommand), which makes all of the files and directories in /opt/unbundledavailable, as shown in the figure below.

[Problem] Docker mounting directory into a file : docker, 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 ERROR:​  you vice versa tutorial trying start rootfs_linux onto mounting failed explained create cannot are docker nginx How to mount a single file in a volume English

Docker compose operate error, 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'. By clicking “Sign up for GitHub”, you agree to when trying to mount an unaccessible/missing file into an to mount a directory onto a file (or vice-versa

Comments
  • What is the output of ls -al .? Wanna see what your pwd looks like.
  • In my case I had accidentally mapped a directory from the host to a file in the container. Restarting the container didn't work anymore. I had to remove the container (docker rm …), then recreate it.
  • Thanks! It works for me starting from the second step and avoiding the last one.
  • I was able to fix the problem by starting on step 2 and also omitting the last one. I did not have to destroy the containers/volumes to mount again.
  • I agree with @MateoHermosilla, it dosen't need to dete the container, only "Reset Credentials"
  • This was the issue for me. Password reset is every few months, so I keep forgetting to reset Shared Drive credentials in Docker.
  • It's like the third time I had this issue, too bad I cannot upvote it everytime lol. Stupid change password policy... Thanks!
  • The command in the original question only listed host volumes as being used. The docker volume command/interface is only for anonymous and named volumes, which are not part of the original question.
  • @programmerq Look at the error, it says that mount was failing when it tried to mount at /var/lib/docker/aufs/mnt/dcea22444e9ffda114593b18fc8b574adfada06947385aedc2ac09f199188fa0\\\" My deduction: It already has a folder due to a previous run, so if you try to map a file to that folder, it would fail.
  • Here two things might have gone wrong, either the host has wrong things, or already created volume has incorrect thing. Assuming host to be correct, I thought it would be better to clear issues with existing volume.
  • This is actually a valid answer for when the container has already been associated with a volume and the type of that volume is being changed in the next run. So removing volume might help!
  • This was helpful. The problem in my case was indeed that I had old containers still defined. Using docker rm to zap them and then doing a docker-compose up worked properly.
  • More details here: github.com/10up/wp-local-docker/issues/…