在 OSX 中安装 Docker 卷时权限被拒绝 [英] Permission denied when mounting Docker volume in OSX

查看:41
本文介绍了在 OSX 中安装 Docker 卷时权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个已经无能为力了,所以希望你们能帮助我.在带有 docker-machine 的 OSX 10.11.2 中,我有一个 docker-compose 文件,它应该构建一个本地 Dockerfile 并将一个 MySQL 容器附加到它.MySQL 容器应该挂载一个本地文件夹,我将在其中存储我的数据库数据,因此如果容器或 VM 出现故障,我可以重新启动它而不会丢失数据.问题是,当我运行它时,它抛出一个权限错误:

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.

我已经尝试了所有我能想到的排列来让它发挥作用.我正在阅读,它可能与 docker-machine 如何处理 OSX 的权限有关,但 docker-machine 的文档说它安装了 /Users 文件夹,所以不应该一个问题.

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.

这是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!

  • 主机 - drwxr-xr-x 7 me 员工 238 Dec 23 12:10 mysql-data/
  • VM - drwxr-xr-x 1 码头工人 238 Dec 23 20:10 mysql-data/

至于容器,它不会在安装卷的情况下运行.没有-v挂载,就是:

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

  • 容器 - drwxr-xr-x 4 mysql mysql 4096 Dec 24 00:37 mysql

推荐答案

这个问题来自于 Mac 和 Linux 分别使用的用户 ID.Mac 不喜欢 Linux 想要使用 1 作为用户 ID.

The issue this comes from is the userids used by Mac and Linux respectively. Mac does not like Linux wanting to use the 1 for the userID.

我在 mac + docker-machine 设置中解决所有权限问题的方法是使用这个 Dockerfile

The way I worked around all the permissions craziness in my mac + docker-machine setup is to use this Dockerfile

FROM mysql:5.6

RUN usermod -u 1000 mysql
RUN mkdir -p /var/run/mysqld
RUN chmod -R 777 /var/run/mysqld

而不是普通的 MySQL 5.6 镜像.

Instead of the plain MySQL 5.6 Image.

最后两行是必需的,因为更改 mysql 用户的用户 ID 会弄乱该图像的构建权限.=> 您需要 777 权限才能在此处运行:/

The last 2 lines are necessary, because changing the userid for the mysql user will mess up the build in permissions for that image. => you need the 777 permissions to make it run here :/

我知道这有点笨拙,但到目前为止,我知道这里是权限问题的最佳解决方案.

I know this is a little hacky, but so far the best solution I know to the permissions issue here.

这篇关于在 OSX 中安装 Docker 卷时权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆