【发布时间】:2015-08-23 17:28:12
【问题描述】:
我在运行 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 up 时,应用程序会加载,但随后我遇到Permission denied @ rb_sysopen 错误。
我的Dockerfile 也比较直截了当:
# Dockerfile
FROM phusion/passenger-ruby21:0.9.17
MAINTAINER meoww- "none@none.com"
# Set correct environment variables.
ENV HOME /root
# Initialize "in production"
ENV RAILS_ENV production
# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]
# Turn on Nginx
RUN rm -f /etc/service/nginx/down
# Remove the default site that comes with Nginx
RUN rm /etc/nginx/sites-enabled/default
ADD nginx.conf /etc/nginx/sites-enabled/my_app.conf
WORKDIR /tmp
ADD Gemfile /tmp/
ADD Gemfile.lock /tmp/
RUN bundle install
ADD . /var/www/my_app
RUN chown -R app:app /var/www/my_app
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
疑难解答
当我修改我的
docker-compose.yml文件并删除volumes:块时,我可以查看我的应用程序。不幸的是,如果我没有volumes:块,那么我需要在每次更改代码后重建 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 并删除 + 重建所有内容(例如 docker rmi [image],然后 docker-compose up 重建了我的图像)。这似乎对此问题没有任何影响。
在这一点上,我倾向于认为我设置 docker-compose 读写权限的方式有问题,但我没有找到任何关于我需要更改的明确文档。
任何建议将不胜感激。
提前致谢。
【问题讨论】:
标签: docker passenger docker-compose