Commands to restore db from dump using psql inside Docker postgresql container

1) docker-compose run app bundle exec rake db:create (Create Database)

2) Docker ps (get container name)

3) docker exec -it database_container_name_1 bash

4) ls (to see if you have backups directory)

5) mkdir backup ( create backup directory if it doesnt exist)

6) docker cp /Users/ganeshprasad/Downloads/db_copy.sql database_container_name_1:/backup (Copy backup file to backup folder inside container)

7) docker exec -it database_container_name_1 bash

8) psql -U db_owner -d db_name -W < backup/db_copy.sql (Restore the db using psql)

9) sudo rm backup/db_copy.sql (to delete backup)



To decode a pdf

attachment =‘Attachment’).first.text
decode_base64_content = Base64.decode64(attachment)
filename = Rails.root.join(‘tmp’, ‘orders’, “#{}-#{SecureRandom.hex(3)}.pdf”)

ensure_tmp_dir_exists_for filename, ‘wb’) do |f|
filepath =
File.unlink filename

def ensure_tmp_dir_exists_for(filename)
Dir.mkdir File.dirname(filename)
rescue Errno::EEXIST

To encode an image

require "base64"

base64_image ="doc/image.png", "rb") do |file|