【问题标题】:Permission denied @ rb_sysopen - log/application.log (Errno::EACCES)权限被拒绝 @ rb_sysopen - log/application.log (Errno::EACCES)
【发布时间】:2016-07-19 08:56:32
【问题描述】:

您好,我正在使用 docker 使用 phusion/passenger 映像部署我的 rails 应用程序。这是我的Dockerfile

FROM phusion/passenger-ruby22:0.9.19

# set correct environment variables
ENV HOME /root
ENV RAILS_ENV production

# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]

# Expose Nginx HTTP service
EXPOSE 80

# Start Nginx / Passenger
RUN rm -f /etc/service/nginx/down

# Remove the default site
RUN rm /etc/nginx/sites-enabled/default

# Add the nginx site and config
ADD nginx.conf /etc/nginx/sites-enabled/nginx.conf
ADD rails-env.conf /etc/nginx/main.d/rails-env.conf

# Let ensure these packages are already installed
# otherwise install them anyways
RUN apt-get update && apt-get install -y build-essential \
                                         nodejs \
                                         libpq-dev

# bundle gem and cache them
WORKDIR /tmp
ADD Gemfile /tmp/
ADD Gemfile.lock /tmp/
RUN gem install bundler
RUN bundle install

# Add rails app
ADD . /home/app/webapp
WORKDIR /home/app/webapp


RUN touch log/delayed_job.log log/production.log log/

RUN chown -R app:app /home/app/webapp
RUN RAILS_ENV=production rake assets:precompile

# Clean up APT and bundler when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

我遇到了tmplog 文件的权限问题。

web_1 | [ 2016-07-19 08:45:12.6653 31/7ff812726700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /home/app/webapp: An error occurred while starting up the preloader.
web_1 |   Error ID: 42930e85
web_1 |   Error details saved to: /tmp/passenger-error-9DeJ86.html
web_1 |   Message from application: Permission denied @ rb_sysopen - log/logentries.log (Errno::EACCES)
web_1 |   /usr/lib/ruby/2.2.0/logger.rb:628:in `initialize'
web_1 |   /usr/lib/ruby/2.2.0/logger.rb:628:in `open'
web_1 |   /usr/lib/ruby/2.2.0/logger.rb:628:in `open_logfile'
web_1 |   /usr/lib/ruby/2.2.0/logger.rb:584:in `initialize'
web_1 |   /usr/lib/ruby/2.2.0/logger.rb:318:in `new'
web_1 |   /usr/lib/ruby/2.2.0/logger.rb:318:in `initialize'
web_1 |   /var/lib/gems/2.2.0/gems/le-2.7.2/lib/le/host/http.rb:37:in `new'
web_1 |   /var/lib/gems/2.2.0/gems/le-2.7.2/lib/le/host/http.rb:37:in `initialize'

我尝试给chmod -R 665/775/777 log/,但仍然没有解决问题。

谢谢

【问题讨论】:

  • 为什么要触摸文件?如果你只是 mkdir log/ 怎么办?
  • 是的,我尝试创建log/ 目录,我什至尝试在mkdir log/ 之后授予777 对该log 目录的权限,但它不工作。这很奇怪。 :( 。我可以让它工作的方法是在我chown我的项目目录之前创建所有需要的日志文件。这对我的日志很有效,但是我在tmp目录中创建随机文件,它们是失败:(

标签: ruby-on-rails-4 nginx docker passenger docker-compose


【解决方案1】:

首先重新排列你的行RUN RAILS_ENV=production rake assets:precompile 然后RUN chown -R app:app /home/app/webapp(在你的 rake 任务之后)所以,它应该是这样的:

RUN RAILS_ENV=production rake assets:precompile RUN chown -R app:app /home/app/webapp

【讨论】:

  • 您能解释一下发生了什么,以及为什么需要按此顺序运行吗?
猜你喜欢
  • 2019-02-13
  • 2020-12-17
  • 2018-07-10
  • 2011-12-28
  • 2015-07-20
  • 2016-03-14
  • 2014-01-24
  • 1970-01-01
  • 2016-05-07
相关资源
最近更新 更多