Are you trying to mount a directory onto a file (or vice-versa)?
TL;DR: Remove the volumes associated with the container.
Find the container name using docker ps -a
then remove that container using:
docker rm -v <container_name>
Problem:
The error you are facing might occur if you previously tried running the docker run
command while the file was not present at the location where it should have been in the host directory.
In this case docker daemon would have created a directory inside the container in its place, which later fails to map to the proper file when the correct files are put in the host directory and the docker command is run again.
Solution:
Remove the volumes that are associated with the container. If you are not concerned about other container volumes, you can also use:
# WARNING, THIS WILL REMOVE ALL VOLUMES
docker volume rm $(docker volume ls -q)
This should no longer happen (since v2.2.0.0), see here
If you are using Docker for Windows, this error can happen if you have recently changed your password.
How to fix:
- First make sure to delete the broken container's volume
docker rm -v <container_name>
Update: The steps below may work without needing to delete volumes first. - Open Docker Settings
- Go to the "Shared Drives" tab
- Click on the "Reset Credentials..." link on the bottom of the window
- Re-Share the drives you want to use with Docker
- You should be prompted to enter your username/password
- Click "Apply"
- Go to the "Reset" tab
- Click "Restart Docker"
- Re-create your containers/volumes
Credit goes to BaranOrnarli on GitHub for the solution.