Setup a Development MySQL Database with Docker

We start from the official MySQL Docker image available: mysql.

FROM mysql:5.7.18

set the ENVironment variable to provide a root password:


and ADD our development setup script init-development.sql:

ADD init-development.sql /docker-entrypoint-initdb.d

Within this SQL file we create all data needed for development purposes.

CREATE USER 'devel'@'%' IDENTIFIED BY 's3cure';

GRANT ALL ON data.* TO 'devel'@'%';

# TODO insert into data table...

Let's create the Docker image:

$ docker build . -t development-mysql

The run the MySQL with

$ docker run -it --rm \
        --publish 3306:3306 \
        --hostname mysql \
        --name mysql \

To test the installation you can either connect into the running container:

$ docker exec -it mysql mysql --user devel --password
| Grants for devel@%                |
| GRANT USAGE ON *.* TO 'devel'@'%' |
1 row in set (0.00 sec)

or run a fresh container to test remote access to the host machine with the IP

$ docker run --rm -it development-mysql mysql --host --user devel --password

Happy SQL development!

For more information on the used SQL commands see:

Show Comments