在 Ubuntu 上运行 docker:安装的主机卷不可从容器中写入 [英] Running docker on Ubuntu: mounted host volume is not writable from container

查看:27
本文介绍了在 Ubuntu 上运行 docker:安装的主机卷不可从容器中写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Docker 对我来说在 Mac 上运行良好,但我必须在 VirtualBox(或 Parallels,或 VMWare Fusion)内运行 docker 主机,因为 Mac 的内核不支持 docker.

Docker works great on a Mac for me, but I have to run docker host inside of a VirtualBox (or Parallels, or VMWare Fusion), since Mac's kernel doesn't support docker.

所以我尝试在 Ubuntu 桌面上设置我的应用程序和 docker-compose - 本地,docker 客户端和 docker 主机在同一系统上物理运行.这有效,但我正在运行的 docker 容器无法写入已安装的主机卷.

So I tried to setup my application and a docker-compose on an Ubuntu Desktop - natively, where both docker client and docker host run physically on the same system. This worked, but my running docker containers can't write into a mounted host volume.

我使用具有以下设置的 docker-compose:

I use docker-compose with the following settings:

volumes:
   - ./api:/usr/src/app

所以我将主机 Ubuntu 操作系统的api"目录挂载到/usr/src/app 下的 docker 容器中.

So I'm mounting the "api" directory of the host Ubuntu OS into docker container under /usr/src/app.

docker inspect 显示卷是可写的

"Destination": "/usr/src/app",
"Mode": "rw",
"RW": true

但事实并非如此:当我尝试从 docker 容器中创建目录或编辑文件时,我得到 permission denied.

However it is not: I get permission denied when I try to create a directory or edit a file from within the docker container.

当然,我在谷歌上搜索了这个问题,我遇到了 CentOS/RHEL 的一些 SELinux 问题,但是我运行的是 Ubuntu 15.10,64 位版本,而不是 CentOS.

I googled for this issue, of course, and I came across a few SELinux issues of CentOS/RHEL, but I'm running Ubuntu 15.10, 64 bit edition, not CentOS.

推荐答案

如果您在主机上的 uid (id -u) 与 uid 那么你可能会遇到这个问题.你可以试试:

If your uid on the host (id -u) isn't the same as the uid of the user in the docker container (often "docker") then you can have this problem. You can try:

  1. 使您的用户和 docker 容器中的用户的 UID 相同.
  2. 将目录的组权限设置为您和 docker 都属于的组的可写权限.
  3. 您也可以使用核选项:

chmod a+rwx -R project-dir/

核选项会使您的 git 工作区变得肮脏,这会让您非常烦恼,因此不是最好的长期解决方案.它可以止血.

The nuclear option will make your git workspace filthy, which will annoy you greatly, so isn't the best long-term solution. It stops the bleeding tho.

为了进一步了解问题,您可能会发现这些有用:

For further understanding the problem, you might find these useful:

  1. https://github.com/docker/docker/issues/7906
  2. https://github.com/docker/docker/issues/7198

这篇关于在 Ubuntu 上运行 docker:安装的主机卷不可从容器中写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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