Pg_restore for postgres running in a docker container

I have a database backup that I would like to restore to the postgres database running inside the docker container.

I am using a docker machine on OS X.
Postgres image postgres:9.4.

This is the script I came with:

pg_restore --verbose --clean --no-acl --no-owner \
  -h tcp://`docker-machine ip default`:5432 \
  -U postgres \
  -d tonsser-api_development latest.dump

But that does not work. I get an error message:

pg_restore: connecting to database for restore
pg_restore: [archiver (db)] connection to database "tonsser-api_development" failed: could not translate host name "tcp://192.168.99.100:5432" to address: nodename nor servname provided, or not known
+4
source share
2 answers

Maybe because you should specify the host and port separately?

-h `docker-machine ip default` -p 5432

See docs

0
source

You should use a connection string, for example. $DATABASE_URL

The following works well for me:

docker-compose exec fooapp pg_restore 
  --verbose --clean --no-acl --no-owner 
  -d $DATABASE_URL foo.dump

( , Rails), :

namespace :db do
  desc 'Import a given file into the database'
  task :import, [:path] => :environment do |_t, args|
    dump_path = args.path
    system 'pg_restore --verbose --clean --no-acl --no-owner -d $DATABASE_URL '\
    + dump_path
  end
end

lib/tasks, - :

docker-compose exec fooapp bundle exec rails db:import[foo.dump]
0

Source: https://habr.com/ru/post/1617967/


All Articles