Skip to content

Instantly share code, notes, and snippets.

@hendisantika
Created June 5, 2017 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hendisantika/42c97f0eea9d4c90cecde139acce141c to your computer and use it in GitHub Desktop.
Save hendisantika/42c97f0eea9d4c90cecde139acce141c to your computer and use it in GitHub Desktop.

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:

ENV MYSQL_ROOT_PASSWORD=s3cr3t

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 \
    development-mysql
To test the installation you can either connect into the running container:

$ docker exec -it mysql mysql --user devel --password
....
mysql> SHOW GRANTS;
+-----------------------------------+
| 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 192.168.1.42:

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

Happy SQL development!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment