简体   繁体   English

在OSX中安装Docker卷时权限被拒绝

[英]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. 在带有docker-machine的OSX 10.11.2中,我有一个docker-compose文件,它应该构建一个本地Dockerfile并为它附加一个MySQL容器。 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. MySQL容器应该挂载我存储数据库数据的本地文件夹,因此如果容器或VM关闭,我可以重新启动它而不会丢失数据。 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. 我正在阅读它可能与docker-machine如何处理OSX的权限有关,但是docker-machine的文档说它安装了/Users文件夹,所以这不应该是一个问题。

Here's the docker-compose.yml : 这是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/ 主持人 - 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/ 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: 没有-v mount,它是:

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

The issue this comes from is the userids used by Mac and Linux respectively. 这个问题来自于Mac和Linux分别使用的用户标识。 Mac does not like Linux wanting to use the 1 for the userID. Mac不喜欢Linux想要将1用作userID。

The way I worked around all the permissions craziness in my mac + docker-machine setup is to use this Dockerfile 我在mac + docker-machine设置中解决所有权限疯狂的方法是使用这个Dockerfile

FROM mysql:5.6

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

Instead of the plain MySQL 5.6 Image. 而不是简单的MySQL 5.6图像。

The last 2 lines are necessary, because changing the userid for the mysql user will mess up the build in permissions for that image. 最后两行是必需的,因为更改mysql用户的用户ID会破坏该映像的构建权限。 => you need the 777 permissions to make it run here :/ =>您需要777权限才能在此处运行:/

I know this is a little hacky, but so far the best solution I know to the permissions issue here. 我知道这有点hacky,但到目前为止我知道权限问题的最佳解决方案。

Try to use the latest docker for mac instead of docker tools. 尝试使用最新的docker for mac而不是docker工具。 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. Docker for Mac不再使用VirtualBox,而是使用HyperKit,这是一种轻量级OS X虚拟化解决方案,构建于OS X 10.10 Yosemite及更高版本的Hypervisor.framework之上。

I suggest also completely remove docker tools(they could co-exist): https://github.com/docker/toolbox/blob/master/osx/uninstall.sh 我建议也完全删除docker工具(它们可以共存): 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. 使用docker for mac,你不必使用权限黑客,它就像在linux版本上一样工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 挂载卷时Docker MySQL无法运行 - Docker mysql failing to run when mounting volume Docker-工具箱 & Win7 | 卷选择权限被拒绝 - Docker-Toolbox & Win7 | permission denied on Volume-Select 使用卷时,MySQL 容器的 Docker 运行失败,出现权限错误 - Catalina MacOS X - Docker run failed for MySQL container with permission errors when using a volume - Catalina MacOS X 使用mysqldump执行MySQL备份时权限被拒绝 - Permission Denied when performing mySQL backup with mysqldump docker 容器的用户权限是否会影响主机对 docker-compose.yml 中挂载卷的权限? - Can user privilege of docker container impact permission of host machine on mounted volume in docker-compose.yml? 从主机驱动器安装容器卷? - Mounting container volume from the hosts' drive? SQLException:在Docker中连接到mysql时访问被拒绝 - SQLException: Access denied when connecting to mysql in docker docker 权限被拒绝 mysql 映像中的 shell 脚本放置在 docker-entrypoint-initdb.d - docker permission denied for shell script in mysql image placed at docker-entrypoint-initdb.d 使用 mariadb 10.4.8 docker 容器使用 docker 组合并在附加外部卷时发出 - Access denied for user 'root'@'localhost' with mariadb 10.4.8 docker container using docker compose and issue while attaching external volume 登录到mysql时权限被拒绝,但能够从cmd digitalocean登录 - permission denied when logging in to mysql, but able to login from cmd digitalocean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM