在Docker容器中运行时,Rails找不到临时目录

时间:2017-04-02 04:22:36

标签: docker docker-compose ruby-on-rails-5

我使用Docker编写了一个非常简单的Rails 5应用程序(及其PostgreSQL数据库)。当我原生运行它时,它工作正常,但如果我在Docker容器内运行它,并转到主页,我收到以下错误:

web_1  | ActionView::Template::Error (could not find a temporary directory):
web_1  |      9:     <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
web_1  |     10:     <%= csrf_meta_tags %>
web_1  |     11: 
web_1  |     12:     <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
web_1  |     13:     <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
web_1  |     14:     <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
web_1  |     15:   </head>
web_1  |   
web_1  | app/views/layouts/application.html.erb:12:in `_app_views_layouts_application_html_erb__1331678602890151203_70235895526140'
web_1  |   Rendering /usr/local/bundle/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout
web_1  |   Rendering /usr/local/bundle/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
web_1  |   Rendered /usr/local/bundle/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (6.5ms)
web_1  |   Rendering /usr/local/bundle/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
web_1  |   Rendered /usr/local/bundle/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.6ms)
web_1  |   Rendering /usr/local/bundle/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
web_1  |   Rendered /usr/local/bundle/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.1ms)
web_1  |   Rendered /usr/local/bundle/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (35.4ms)

我在其他帖子中看到它可能取决于容器内/tmp目录的权限,所以我给了它完全权限,我也尝试指定TMPDIR容器的目录,但它没有用。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

遇到了同样的问题,我认为你的docker root不是&#39; / var / lib / docker&#39;但是位于文件系统树中的其他位置。

在我的情况下,docker root位于使用NTFS格式化的外部SSD上。但是,此文件系统不支持临时目录所需的权限,该临时目录位于&#39; / tmp /&#39;之下。所以我调整了磁盘的大小,创建了一个额外的EXT4分区并配置了docker来将其数据存储在该分区上。这解决了这个问题。

如果这不起作用,请尝试以下命令:     chmod + t / tmp 例如:     chmod + t / var / lib / docker / tmp