How to push a local database dump into a docker container?

I tried:

ssh root@mytutumnode "docker exec -ti mydockercontainerid su postgres -c 'psql mydatabasename'" < mydump.sql

but it executes only

  • docker best way to run mysql
  • Why the directory created after WORKDIR disappear
  • What is the difference between Cloud Foundry and Docker?
  • Getting “broken pipe” when building Docker image using boot2docker Mac
  • Working on a Dockerfile in order to build a WordPress image
  • AWS Elastic Beanstalk VPC - HTTPS from ELB to instance
  • ssh root@mytutumnode "docker exec -ti mydockercontainerid su postgres -c 'psql mydatabasename'"
    

    … and omits < mydump.sql part.

    psql --list and alikes do work.

  • How to clone and customise laravel homestead and install more things in it?
  • Unable to pull the images in docker on Windows
  • Trying to execute easy_install or pip on docker build says command not found
  • How to setup a development environment for java in unix for each of the team member
  • Docker: RVM command not found
  • Vagrant using docker as provider on MacOS, impossible to mount directory in container
  • One Solution collect form web for “How to push a local database dump into a docker container?”

    Here’s the Makefile i ended up using:

    # Convenience cli shortcuts
    
    LOCAL_DOCKER_IP = 192.168.99.100
    STAGING_IP = DOCKER_NODE_IP_HERE
    RELEASE_IP = IP_FROM_THE_SERVER_WITH_THE_ORIGINAL_DB
    
    DOCKER_DB_ID = $(shell ssh root@$$STAGING_IP "docker ps | grep database" | awk '{print $$1}')
    
    
    download_staging_db:
        psql -h $(LOCAL_DOCKER_IP) -p 5432 -U postgres -c 'drop database mydb'
        psql -h $(LOCAL_DOCKER_IP) -p 5432 -U postgres -c 'create database mydb'
        ssh root@$(STAGING_IP) "docker exec $(DOCKER_DB_ID) su postgres -c 'pg_dump mydb'" | psql -h $(LOCAL_DOCKER_IP) -p 5432 -U postgres mydb
    
    upload_release_db_to_staging_db:
        ssh root@$(RELEASE_IP) "cd / && su postgres -c 'pg_dump my db'" > temp.sql
        scp temp.sql root@$(STAGING_IP):/temp.sql
        ssh root@$(STAGING_IP) "docker cp /temp.sql $(DOCKER_DB_ID):/temp.sql"
        ssh root@$(STAGING_IP) "docker exec $(DOCKER_DB_ID) su postgres -c 'drop database mydb'"
        ssh root@$(STAGING_IP) "docker exec $(DOCKER_DB_ID) su postgres -c 'create database mydb'"
        ssh root@$(STAGING_IP) "docker exec $(DOCKER_DB_ID) su postgres -c 'psql mydb < /temp.sql'"
        rm temp.sql
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.