title: How to connect Mysql Docker to other docker in Dockerfile?
body: <p>I am using these Docker commands:</p>
  
  <pre><code>docker network create --subnet=172.18.0.0/16 magentonet
  docker run -d --name mysql -p 3306:3306 --net magentonet --ip 172.18.0.23 -e MYSQL_ROOT_PASSWORD=magepass -e MYSQL_DATABASE=mySchema mysql:5
  docker build -t magento-bdd .
  docker run --net magentonet --ip 172.18.0.22 -d magento-bdd
  </code></pre>
  
  <p>When the command <code>docker build -t magento-bdd .</code> runs, I have this RUN command in there:</p>
  
  <pre><code>mysql --host=172.18.0.23 --user=root --password=magepass -e "create database magentodb; create user magentouser@localhost; grant all privileges on magentodb.* to 'magentouser'@'%' IDENTIFIED BY 'magentopass'; flush privileges;"
  </code></pre>
  
  <p>The problem I face now, is that the command ends with <code>ERROR 2003 (HY000): Can't connect to MySQL server on '172.18.0.23' (110)</code></p>
  
  <p>This kinda makes sense because I haven't connected the container to the network yet (this will happen in the <code>run</code> command.</p>
  
  <p>How can I already store something in the database of the previous build Docker from the Dockerfile?</p>