Table of Contents
Docker images of MariaDB 10.0 build on Debian Jessie. Admin user, password, host and ports can be set using environmental variables.
$ git clone https://github.com/bremme/docker-mariadb.git
$ sudo docker build -t bremme/mariadb .
$ sudo docker run \
--env=MYSQL_ADMIN_PASS=password \
--publish=3306:3306 \
--name=mariadb \
--detach=true \
bremme/mariadb
To connect to the MariaDB instance you will need the containers IP address (and port). You can grab this from stdout:
$ sudo docker logs mariadb
Or you could use docker inspect:
$ sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' mariadb
Once you have the IP (and port) you can just connect to the database using any client, for example using the mysql cli client:
$ mysql -h<container_ip_address> -p<container_published_port \
-uadmin -p<password>
It's recommended to use a separate data only container which exposes two volumes: "/etc/mysql" and "/var/lib/mysql". These volumes will be mounted in the MariaDB containerer using "--volumes-from". Furthermore for some added security I'm using a file "__private_vars.env" to pass in the admin database user and password. Be sure to restrict permissions (e.g. "chmod 400") and add to (global) .gitignore.
docker run \
--env-file=__private_vars.env \
--volumes-from=data-mariadb \
--volume=/etc/timezone:/etc/timezone:ro \
--publish=3306:3306 \
--name mariadb \
--restart=always \
--detach=true \
bremme/mariadb
For convienence the above command have been added to a run script:
$ sudo ./run