Docker “Mounts denied” Error Fix
I was recently bringing up a Docker container with a WordPress build, when I encounter this error in the console:
[+] Running 2/0
✔ Container dcidev-mysql Runnin... 0.0s
✔ Container dcidev-wordpress Re... 0.0s
Attaching to dcidev-mysql, dcidev-wordpress
Error response from daemon: Mounts denied:
The path /users/hsnyc/hosts/clients/dci/wordpress is not shared from the host and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.
See https://docs.docker.com/desktop/mac for more info.
Or you see the error in the Docker Desktop App:
After one hour of searching and trying various things including a PHP upgrade, WordPress image upgrade, deleting the container and re-downloading.. and nothing worked.
The Fix that worked for me:
This error was happening because I had the path written as a relative path in the docker-compose.yml
file:
volumes:
- ./wordpress/:/var/www/html
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
I update the file with absolute path and after I made this edit and re-started Docker, it worked fine:
volumes:
- /Users/henry/hosts/dci/wordpress/:/var/www/html
- /Users/henry/hosts/dci/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
For reference, I was using the following version of Docker and of Mac OS:
Mac OS: Venture 13.5
Docker Desktop: v.4.22.0
Hope this is helpful.