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

我用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) 

我读过其他post,它可能取决于容器内的/tmp目录的权限,所以我给了它完全的权限,我也试着指定容器的TMPDIR目录,但它没有工作。

有任何想法吗?

有了同样的问题,我认为你的docker根不是'/ var / lib / docker',而是位于文件系统树的其他地方。

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

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