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 container can only access internet with --net=host
  • What's the mechanism of Inner Load Balancing along with docker swarm v1.12
  • Debug a NodeJS application inside Docker
  • Docker environment variable and Django database setup
  • GCE Build Fails
  • Docker Image to run on any flavor of Linux
  • ssh root@mytutumnode "docker exec -ti mydockercontainerid su postgres -c 'psql mydatabasename'"
    

    … and omits < mydump.sql part.

    psql --list and alikes do work.

  • Docker fedora hbase JAVA_HOME issue
  • “supervisor dead but pid file exists” while trying to start hue in dockerfile
  • Spotify docker-gc: prevent auto stop after first run
  • Docker - Ubuntu - Nginx - MariaDB - Connection refused
  • How do I configure amount of RAM to be used by kalabox on Ubuntu
  • Connect nginx on host with wsgi unicorn inside docker 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.