title: Error when creating a MySQL database in a Dockerfile
body: <p>I want to create a simple container that contains a MySQL server with an initialized database. My Dockerfile currently looks like this:</p>
  
  <pre><code>FROM ubuntu:16.10
  
  RUN apt-get update
  
  # install MySQL; root user with no password
  ENV DEBIAN_FRONTEND noninteractive
  RUN apt-get install -y mysql-server mysql-client
  
  RUN service mysql start
  RUN mysqladmin -u root create mydb
  
  CMD [ "bash" ]
  </code></pre>
  
  <p>However, when I build the image via <code>docker build -t mysql-test .</code> I get the following error:</p>
  
  <pre><code>Step 7 : RUN mysqladmin -u root create mydb
   ---&gt; Running in a35c3d176d4f
  mysqladmin: connect to server at 'localhost' failed
  error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)'
  Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
  The command '/bin/sh -c mysqladmin -u root create mydb' returned a non-zero code: 1
  </code></pre>
  
  <p>When I comment the line where I want to create the database (<code>RUN mysqladmin -u root create mydb</code>) I can build the image, start it, and execute the mysqladmin command from the command line:</p>
  
  <pre><code># this works
  &gt; docker run -it mysql-test
  root@...&gt; service mysql start
  root@...&gt; mysqladmin -u root create mydb
  </code></pre>
  
  <p>Why do I get the error when creating the database in the Dockerfile? Thank you!</p>