Can't create tempfile inside docker

kjdelys kjdelys posted on 2024-07-23 22:14:10 UTC

Hello guys,
i'm having an issue with my rails app deployed with docker. Every time app goes through a code using tempfile i
t raises an error .

system temporary path is not writable: /tmp
11:00:30 web.1    | /tmp is not writable: /tmp
11:00:30 web.1    | . is not writable: /rails
11:00:30 web.1    | 2024-07-22 11:00:30 +0000 Rack app ("POST /folders/dropzone_import" - (82.64.63.1)): #<ArgumentError: could not find a temporary directory>

ruby "3.0.2"
gem "rails", "~> 7.1.3.1"
on ubuntun 22.04


David Kimura PRO said 3 months ago :
You could try to create a .keep file in the tmp folder. Make sure your .dockerignore isn't excluding the tmp folder.

Something like this is in the Rails main's .dockerignore.

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

kjdelys PRO said 3 months ago :
Hey Thanks   David Kimura  
i have that. still not working. it keeps raising the same error with 
Tempfile.new

David Kimura PRO said 3 months ago :
Ah, the /tmp it is referring to may be the system tmp folder. You may want to see if you can create the tempfile within your Rails folder's tmp. My thought is that the dockerfile is changing the user and this user doesn't have access to write there.

kjdelys PRO said 3 months ago :
yeah.


require 'fileutils'

unless Rails.env.development?
  # force the whole app to use its own tmpdir
  FileUtils.mkdir_p(Rails.root.join('tmp'))
  ENV['TMPDIR'] = Rails.root.join('tmp').to_s
end


in initializer fix everything

Login to Comment
Back to forums