Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied when mounting Docker volume in OSX

I'm at my wit's end with this, so hopefully you folks can help me. In OSX 10.11.2 with docker-machine, I've got a docker-compose file that should build a local Dockerfile and attach a MySQL container to it. The MySQL container should mount a local folder where I'm storing my database data, so if the container or VM comes down, I can just restart it without data loss. Problem is, when I run it, it throws a permissions error:

db_1  | 2015-12-23 19:17:59 7facaa89b740  InnoDB: Operating system error number 13 in a file operation.
db_1  | InnoDB: The error means mysqld does not have the access rights to
db_1  | InnoDB: the directory.

I've tried every permutation I can think of to get this to work. I was reading around and it may have something to do with how docker-machine handles permissions with OSX, but the documentation for docker-machine says that it mounts the /Users folder, so that shouldn't be an issue.

Here's the docker-compose.yml:

web:
  build: .
  ports:
    - "3000:3000"
  links:
    - db
db:
  image: mysql:5.6
  ports:
    - "3306:3306"
  volumes:
    - /Users/me/Development/mysql-data:/var/lib/mysql
  environment:
    MYSQL_ROOT_PASSWORD: mypass

Any ideas? I can't help but think it's something really simple. Any help would be most appreciated!

Edit:

  • Host - drwxr-xr-x 7 me staff 238 Dec 23 12:10 mysql-data/
  • VM - drwxr-xr-x 1 docker staff 238 Dec 23 20:10 mysql-data/

As to the container, it won't run with the volume mounted. Without the -v mount, it is:

  • Container - drwxr-xr-x 4 mysql mysql 4096 Dec 24 00:37 mysql
like image 634
greggilbert Avatar asked Dec 23 '15 19:12

greggilbert


People also ask

How do I fix Docker permission denied?

Method 2: Run Docker Commands with sudo The "Permission Denied" error appears only with non-root users. Running the command with sudo to acquire root privileges usually resolves the issue.

How do I fix Docker got permission denied while trying to connect to the Docker daemon socket?

Fix 1: Run all the docker commands with sudo If you have sudo access on your system, you may run each docker command with sudo and you won't see this 'Got permission denied while trying to connect to the Docker daemon socket' anymore.


1 Answers

Try to use the latest docker for mac instead of docker tools. Docker for Mac no longer uses VirtualBox, but rather HyperKit, a lightweight OS X virtualization solution built on top of Hypervisor.framework in OS X 10.10 Yosemite and higher.

I suggest also completely remove docker tools(they could co-exist): https://github.com/docker/toolbox/blob/master/osx/uninstall.sh

With docker for mac, you don't have to use permission hacks, it would just work like it would be on a linux build.

like image 52
Alan Avatar answered Nov 16 '22 00:11

Alan