Phusion Passenger和Docker-Compose with Permissions(Phusion Passenger and Docker-Compose Issue with Permissions)

我在运行docker-compose和Phusion Passenger的docker镜像时遇到了权限问题。

具体来说,错误是: Permission denied @ rb_sysopen - /var/www/my_app/tmp/.....

我docker-compose.yml文件包含以下信息:

happy_passenger: build: . container_name: happy_passenger ports: - "80:80" volumes: - .:/var/www/my_app links: - redis redis: container_name: my_redis image: redis ports: - "6379:6379"

故障排除

当我修改docker-compose.yml文件并删除volumes: block时,我能够查看我的应用程序。 不幸的是,如果我没有volumes: block,那么我需要在每次更改代码后重建docker镜像。 所以这个选项不起作用。

我注意到,当应用程序启动时,我也看到了权限错误:

App 66 stderr: Rails Error: Unable to access log file. Please ensure that /var/www/my_app/log/development.log exists and is writable (ie, make it writable for user and group: chmod 0664 /var/www/my_app/log/development.log)

根据上面的错误(#2),我尝试将RUN chmod -R 0664 /var/www/my_app到我的Dockerfile并删除+重建所有内容(例如Dockerfile docker rmi [image] ,然后使用docker-compose up重建我的图像) 。 这似乎没有对这个问题产生任何影响。


在这一点上,我倾向于认为我设置docker-compose读写权限的方式有问题,但我没有找到任何关于我需要更改的明确文档。

任何意见,将不胜感激。

提前致谢。

I am encountering a permissions issue when running docker-compose and Phusion Passenger's docker image.

Specifically, the error is: Permission denied @ rb_sysopen - /var/www/my_app/tmp/.....

My docker-compose.yml file contains the following information:

happy_passenger: build: . container_name: happy_passenger ports: - "80:80" volumes: - .:/var/www/my_app links: - redis redis: container_name: my_redis image: redis ports: - "6379:6379"

Troubleshooting

When I modify my docker-compose.yml file and remove the volumes: block, I am able to view my application. Unfortunately, if I don't have a volumes: block, then I am required to rebuild the docker image after every code change that I make. So that option will not work.

I noticed that when the application starts, I'm seeing a permissions error too:

App 66 stderr: Rails Error: Unable to access log file. Please ensure that /var/www/my_app/log/development.log exists and is writable (ie, make it writable for user and group: chmod 0664 /var/www/my_app/log/development.log)

Per the error above (#2), I tried adding a RUN chmod -R 0664 /var/www/my_app to my Dockerfile and removing + rebuilding everything (e.g. docker rmi [image], then docker-compose up which rebuilt my image). This didn't seem to have any impact on this issue.


At this point, I'm inclined to think that there's something wrong with the way I'm setting up the docker-compose read-write permissions, but I am not finding any clear documentation on what I need to change.

Any advice would be appreciated.

Thanks in advance.

最满意答案

似乎问题是boot2docker的一个错误以及它如何在OSX上安装卷。 首先,我运行命令docker inspect happy_passenger 。 这给了我关于我的音量的以下信息:

"Mounts": [ { "Source": "/Users/meow/test/www/demodocker", "Destination": "/var/www/my_app", "Mode": "rw", "RW": true } ],

当启用读/写(R / W)时,卷在docker中显示。 在正常情况下,这表明我应该能够使用已安装的卷并写入文件系统。 但是,由于R / W权限存在错误,因为权限错误,我遇到了各种错误。 甚至运行chmod -R 777 . 在共享和主机目录上没有解决问题

为了解决这个问题,我做了以下事情:

在我的dockerfile

# Dockerfile FROM phusion/passenger-ruby21:0.9.17 MAINTAINER meoww- "none@none.com" # Hack to get around the boot2docker issue. RUN usermod -u 1000 app RUN usermod -G staff app

添加两个命令RUN usermod -u 1000 app和RUN usermod -G staff app我可以在使用docker-compose up时成功加载我的容器化应用程序。

希望这有助于某人修复他们的docker权限错误/ docker挂载量bug。

另外,这里是Github中问题的链接:

https://github.com/boot2docker/boot2docker/issues/581

It appears that the issue is a bug with boot2docker and how it mounts volumes on OSX. First, I ran the command docker inspect happy_passenger. This gave me the following information about my volume:

"Mounts": [ { "Source": "/Users/meow/test/www/demodocker", "Destination": "/var/www/my_app", "Mode": "rw", "RW": true } ],

The volume was showing up in docker as Read/Write (R/W) enabled. Under normal circumstances, this would indicate that I should be able to use a mounted volume and write to the file system. However, since a bug exists with the R/W permissions, I was encountering various errors due to the fact that the permissions were wrong. Even running chmod -R 777 . on the shared and host directories did not fix the issue

To fix this, I did the following:

In my dockerfile

# Dockerfile FROM phusion/passenger-ruby21:0.9.17 MAINTAINER meoww- "none@none.com" # Hack to get around the boot2docker issue. RUN usermod -u 1000 app RUN usermod -G staff app

After adding the two commands RUN usermod -u 1000 app and RUN usermod -G staff app I was able to successfully load up my containerized application when using docker-compose up.

Hope this helps someone fix their docker permission errors/docker mounted volume bug.

Also, here's a link to the issue in Github:

https://github.com/boot2docker/boot2docker/issues/581

更多推荐