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

  • Cannot reach “static-mapped” docker container from another container on the same host
  • How to setup a MongoDB with Vagrant and Docker
  • DB, user not created using postgres docker-compose
  • Connecting Docker container to corporate LDAP server through SSL
  • Is it possible to allow the containers running on the same image to share their filesystem?
  • Docker installation issues on Windows 10 Home Edition
  • ssh root@mytutumnode "docker exec -ti mydockercontainerid su postgres -c 'psql mydatabasename'"
    

    … and omits < mydump.sql part.

    psql --list and alikes do work.

  • Elastic beanstalk: Failed to buld docker image
  • Setting Stackdriver Logging log level for Docker's gcplogs log driver
  • Managing Docker containers from Ansible plays
  • docker-compose build doesn't re-create some slices of my container, resulting in partially obsolete code
  • Docker and Java 9 modules
  • Is there a way for docker-compose to save and open a docker image?
  • 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.