How restore a postgres database with fig?

I’m trying to use FIG (http://www.fig.sh/) for a django app. I can’t recreate the database from a dump, I try:

fig run db pg_restore -d DBNAME < backup.sql

And get:

  • Docker-compose Kubernetes ENV properties interoperability
  • How to connect to a Bitcoin testnet running in a docker container
  • create file in shared folder docker container
  • How can I run containers detached and have them automatically removed when they exit?
  • Why does using DOCKER_OPTS=“--iptables=false” break the DNS discovery for docker-compose?
  • Docker Image for creating a windows virt and download files to it
  • socket.error: [Errno 104] Connection reset by peer

    But this run (still not see the tables in the db):

    fig run db pg_restore < backup.sql
    

    This is the dockerfile:

    FROM python:3.4
    ENV PYTHONUNBUFFERED 1
    RUN mkdir /code
    WORKDIR /code
    ADD requirements.txt /code/
    ADD backup.sql /code/
    RUN pip install -r requirements.txt
    RUN pg_restore -d postgres  backup.sql
    ADD . /code/
    

    And fig.yml:

    db:
      image: postgres
      ports:
        - 5432  
    web:
      build: .
      command: python manage.py runserver 0.0.0.0:8000
      volumes:
        - .:/code
      ports:
        - "8000:8000"
      links:
        - db
    

  • Unable to deploy my application to remote docker
  • How do I deploy to a remote docker host on windows server 2016?
  • `data-container` with named or anonymous volumes - conceptual problems? (Discussion)
  • Setting up a local docker swarm w/o physical network
  • Why does my postgres data disappear after loading it from a backup?
  • Docker Cluster loses leader status after reboot
  • One Solution collect form web for “How restore a postgres database with fig?”

    When you run

    fig run db pg_restore -d DBNAME < backup.sql
    

    postgresd is not running. You’ve replaced the startup of the daemon with the pg_restore command.

    I would suggest doing something like this:

    1. Move backup.sql to dockerfiles/db/backup.sql
    2. Create a dockerfiles/db/Dockerfile
    3. change your fig.yml to use build for the db instead

    Dockerfile

    FROM postgres
    ADD . /files
    WORKDIR /files
    RUN /etc/init.d/postgresql start && \
        pg_restore -d DBNAME < backup.sql && \
        /etc/init.d/postgresql stop
    

    fig.yml

    db:
        build: dockerfiles/db
    

    Now when you run any fig commands your database should be ready to go

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