A script to readily create and run MariaDB in Docker. This also builds phpMyAdmin in docker for accessing the MariaDB (Mysql) server.
There are default values for the MariaDB docker container name, the port that MariaDB uses, the Mysql username, the Mysql password, and the root Mysql password. These may be overridden by setting the following environment variables (see more details on MariaDB/Mysql specific environment variables here):
-
MARIADB_VERSION
The version of MariaDB/Mysql. (The default islatest) -
MARIADB_CONTAINER
The MariaDB/Mysql docker container name. (The default ismariadb-docker) -
MARIADB_PORT
The port used by MariaDB/Mysql. (The default is3306) -
MYSQL_DATABASE
Specifies the name of a database to be created on image startup. (The default is no initial database.) -
MYSQL_USER
The MariaDB/Mysql username. (The default ismariadb. This should be fine for development, but PLEASE use best practices and change for any deployment.) -
MYSQL_PASS
The MariaDB/Mysql password. (The default isdocker. This should be fine for development, but PLEASE use best practices and change for any deployment.) -
MYSQL_ROOT_PASSWORD
The root MariaDB/Mysql password. (The default isdocker. This should be fine for development, but PLEASE use best practices and change for any deployment.)
There are default values for the phpMyAdmin docker container and the port that phpMyAdmin uses. These may be overridden by setting the following environment variables:
-
PMA_CONTAINER
The phpMyAdmin docker image name. (The default ispg-admin) -
PMA_PORT
The port used by phpMyAdmin. (The default is8081) -
PMA_UPLOAD_LIMIT
The default upload limit (for importing SQL). (The default is10M)
Once created these containers may be accessed via a network. The default network is called mariadb. This may be overridden by setting the following environment variable:
MARIADB_NETWORK
The network the containers can be reached on. (The default ismariadb). From the host machine, the DB is in localhost, within the container (ie. from phpMyAdmin) the DB is found at this location.
A .env file may be placed in the same folder as this script to set environment variables. An example of the content of the .env may look like:
MARIADB_NETWORK=my_different_network
PMA_PORT=4242.env-sample may be used as a template.
Simply run:
cp .env-sample .envThis creates docker containers for a mysql database and phpMyAdmin. The data persists across container restarts, it is stored in Docker.
Running this script without overriding any variables (see above) should work just fine for a development environment.
Example usage:
To start the containers, simply call:
./start.shIf a rebuild is desired, pass the "build" flag, --build or simply -b:
./start.sh --buildor simply
./start.sh -bIf environment variables need to be reset to defaults (with .env overrides), pass the "reset_env" flag, --reset_env or simply -r:
./start.sh --reset_envor simply
./start.sh -rThis script will stop the containers. They can be restarted with the start.sh script and the data will persist.
Example usage:
./stop.shThe default root user is root. That user will have ALL the privileges. The MYSQL_USER will be granted all access (corresponding to GRANT ALL) to the MARIADB_DATABASE database.