title: How to restore MySQL dump from host to Docker container
body: <p>I'm sure this is a duplicated topic, but I simply cannot get it done: I like to restore my database dump to MySQL container in run time, without modifying the <em>docker-compose.yml</em> file.</p>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>FROM php:5.4.45-apache
  RUN apt-get update
  RUN docker-php-ext-install mysql mysqli
  </code></pre>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>version: '2'
  services:
    php_service:
      container_name: my_php
      # Use Dockerfile in this dir to build the image
      build: .
      # Stop containers always after exiting.
      restart: always
      ports:
        # 'localhost' does not works from the host, but the IP of docker itself
        # (192.168.99.100 for example - shown on the top of the console)
        - "80:80"
        - "443:443"
      environment:
        # Pass variables
        - API_TOKEN=xxxx
      volumes:
        # The current directory will be mounted to '/var/www/html'
        # WORKS ONLY IN USER'S DIR ON WINDOWS (~/Downloads for example)
        - .:/var/www/html
    # See https://hub.docker.com/_/mysql/ for additional information.
    # To open up console, run `docker exec -it my_mysql bash`.
    # To restore a dump `docker exec -i my_mysql /usr/bin/mysql -u root
    # --password=test_pass DATABASE &lt; DUMP.sql` should work, but it never did.
    mysql_service:
      container_name: my_mysql
      # Use an existing image
      image: mysql:5.6
      restart: always
      ports:
        # Let it accessible for other apps (mysql on host, IDE, etc.)
        - "3306:3306"
      environment:
        MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
        MYSQL_USER: 'test'
        MYSQL_PASS: 'pass'
      volumes:
        # Named volumes (my-datavolume) has to be listed in the "volumes"
        # section - I don't know how it works or what is it doing at all...
        # (-_-')
        - my-datavolume:/var/lib/mysql
  volumes:
    my-datavolume:
  </code></pre>
  
  <p>Steps to reproduce:</p>
  
  <ul>
  <li>Start Docker Toolbox on Windows 7 host</li>
  <li><code>docker-compose up</code></li>
  <li>Open a new Docker Toolbox terminal</li>
  <li><code>docker exec my_msql /usr/bin/mysql -u root --password=test_pass -e 'CREATE DATABASE testdb;'</code></li>
  <li><code>docker exec -i my_mysql /usr/bin/mysql -u root --password=test_pass testdb &lt; dump_on_host.sql</code></li>
  <li><code>docker exec -it my_mysql /usr/bin/mysql -u root --password=test_pass testdb</code></li>
  <li><code>mysql&gt; SHOW TABLES;</code></li>
  </ul>
  
  <p>The database is empty. It seems that it does nothing, because the terminal responds too quickly. I tried out the dump by installing MySQL on my host, it can be restored.</p>