I want to create a simple container that contains a MySQL server with an initialized database. My Dockerfile currently looks like this:
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" ]
However, when I build the image via docker build -t mysql-test .
I get the following error:
Step 7 : RUN mysqladmin -u root create mydb
---> 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
When I comment the line where I want to create the database (RUN mysqladmin -u root create mydb
) I can build the image, start it, and execute the mysqladmin command from the command line:
# this works
> docker run -it mysql-test
root@...> service mysql start
root@...> mysqladmin -u root create mydb
Why do I get the error when creating the database in the Dockerfile? Thank you!