title: How to commit changed data in a mysql container to a new image
body: <p>I am trying to create a custom docker image with mysql database in it. I don't need to mount volumes or persist any data between container runs and removals. The goal is to always start containers in the same state. Use them for tests and remove them.</p>
  
  <p>Steps taken:</p>
  
  <p>Start a mariadb container from a generic mariadb image.</p>
  
  <pre><code>docker run --name some-mariadb -e MYSQL_ROOT_PASSWORD=root -d mariadb:10.1.24
  1a657ebec5ba
  </code></pre>
  
  <p>Connect to db with mysql client to create a db, user and grant permissions.</p>
  
  <pre><code>mysql -uroot -proot -h 0.0.0.0
  
  mysql&gt; CREATE DATABASE store
  
  mysql&gt; CREATE USER 'store'@'%' IDENTIFIED BY 'store';
  
  mysql&gt; GRANT ALL ON store.* TO 'store'@'%';
  
  mysql&gt; exit
  </code></pre>
  
  <p>Import data.</p>
  
  <p><code>mysql -ustore -pstore -h 0.0.0.0 store &lt; ~/mysqldumps/store-2017-06-22-13-55.sql</code></p>
  
  <p>At this point the container has the needed user, permissions, data and database.</p>
  
  <p>Commit to the new image.</p>
  
  <p><code>docker commit 1a657ebec5ba my-registry/store-test-db:2017-06-30-15-26</code></p>
  
  <p>Now, when I start a container from this image on another host. Its just a plain mysql container without my user or database. </p>
  
  <p>What is the correct way to create such image?</p>