title: How to execute mysqldump command from the host machine to a mysql docker container
body: <p>I want to create mysql dumps for a database which is running in docker container. However I do not want to get into the container and execute the command but do it from the host machine. Is there a way to do it. I tried few things but probably I am wrong with the commands.</p>
  <p><code>docker exec -d mysql sh mysqldump -uroot -pSomePassword DBName &gt; /dumps/MyNewDump.sql</code></p>
  <p><code>docker exec -d mysql sh $(mysqldump -uroot -pSomePassword DBName &gt; /dumps/MyNewDump.sql)</code></p>
  <p><code>docker exec -d mysql mysqldump -uroot -pSomePassword DBName &gt; /dumps/MyNewDump.sql</code></p>
  <p>the <code>dumps</code> directory is already bind to the host machine.</p>
  <p>These commands are seems not the right way to do it or probably not the right way to do it at all. These always ends up with an error:</p>
  <blockquote>
  <p>bash: /dumps/MyNewDump.sql: No such file or directory</p>
  </blockquote>
  <p>But if I just run <code>mysqldump -uroot -pSomePassword DBName &gt; /dumps/MyNewDump.sql</code> inside the container it works fine.</p>