Import a heroku postgres database dump into a docker database container with boot2docker

I’m running boot2docker on OSX 10.10. I have a database container set up so my databases don’t get reset every time I start/stop a container. I would like to import a dump of a postgres database from heroku into my docker database. Is this possible to do?

  • cannot open shared object file
  • Making multiple Docker Machines accessible across local network. Linux & Mac
  • Expose mongo port in other container
  • Isolated Docker containers and resource limiting
  • make not found with Dockerfile and centos:7 image
  • confd newbie trying to get if in template to work getting “invalid type for comparison”
  • Docker error from CMD command prompt: Something went wrong running an SSH Command
  • How to link selenium server via docker compose
  • How do I connect a Docker container running in boot2docker to a network service running on another host?
  • Modify Node stack trace paths for use in Docker containers
  • When using docker-compose to fire up containers how do I programatically get their ips?
  • How can I force ssl connections in Percona server using Docker?
  • One Solution collect form web for “Import a heroku postgres database dump into a docker database container with boot2docker”

    I ended up finding this out with the help of a coworker. It’s a little bit harder than just a regular old postgres database, but not much. This is based off this stackoverflow answer.

    1. Generate your heroku database dump download url: heroku pgbackups:url
    2. Start a bash shell on your postgres container. On my system this container was named pg: fig run db bash
    3. Install curl: apt-get update && apt-get install curl
    4. Download the database dump using curl: curl -o latest.dump [PASTE THE OUTPUT OF STEP 1 HERE]
    5. Import the dump (note, database name and username can be found in fig.yml and database.yml respectively): pg_restore --verbose --clean --no-acl --no-owner -h [YOUR BOOT2DOCKER IP] -U [YOUR_USERNAME] -d [DATABASE_NAME] latest.dump

    And there you have it!

    If the last step fails with some kind of invalid database error, double check latest.dump with head latest.dump. If you feel like your database is not downloading correctly, you may want to manually download it via the web gui and upload it to another host, like drop box. Then you would substitute step 1 with whatever url your dump can be found at.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.