MariaDB Docker image
This repository contains Dockerfile for MariaDB server 10.1 based on baseruntime for the Fedora 26 Boltron general usage.
For more information about modules see official Fedora Modularity documentation.
In default Dockerfile we use
boltron-preview:latest image, which consists dnf prototype with modularity functionality. This means command:
dnf install -y mariadb && dnf clean all && \ will install not only mariadb package but mariadb module with the default profile, which in this case suppose to install mariadb, mariadb-server, gettext, policycoreutils and several other packages as dependecy. If one need to install single package, the
--rpm parameter need to be set before package name.
docker build -t mariadb_microdnf:latest -f Dockerfile.microdnf . will create MariaDB docker image from baseruntime and using
microdnf to install
mariadb, mariadb-server and their dependencies and packages needed to run the container.
Environment variables and volumes
The image recognizes the following environment variables that you can set during
initialization by passing
-e VAR=VALUE to the Docker run command.
||User name for MySQL account to be created|
||Password for the user account|
||Password for the root user (optional)|
The following environment variables influence the MySQL configuration file. They are all optional.
||Sets how the table names are stored and compared||0|
||The maximum permitted number of simultaneous client connections||151|
||The maximum size of one packet or any generated/intermediate string||200M|
||The minimum length of the word to be included in a FULLTEXT index||4|
||The maximum length of the word to be included in a FULLTEXT index||20|
||The number of open tables for all threads||400|
||The size of the buffer used for index blocks||32M (or 10% of available memory)|
||The size of the buffer used for sorting||256K|
||The size of the buffer used for a sequential scan||8M (or 5% of available memory)|
||The size of the buffer pool where InnoDB caches table and index data||32M (or 50% of available memory)|
||The size of each log file in a log group||8M (or 15% of available available)|
||The size of the buffer that InnoDB uses to write to the log files on disk||8M (or 15% of available memory)|
||Point to an alternative configuration file||/etc/my.cnf|
||Set sets the binlog format, supported values are
You can also set the following mount points by passing the
-v /host:/container flag to Docker.
|Volume mount point||Description|
||MySQL data directory|
Notice: When mouting a directory from the host into the container, ensure that the mounted
directory has the appropriate permissions and that the owner and group of the directory
matches the user UID or name which is running inside the container.
If you want to set only the mandatory environment variables and not store
the database in a host directory, execute the following command:
$ docker run -d --name mariadb_database -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -p 3306:3306 modularitycontainers/mariadb:latest
This will create a container named
mariadb_database running MySQL with database
db and user with credentials
user:pass. Port 3306 will be exposed and mapped
to the host. If you want your database to be persistent across container executions,
also add a
-v /host/db/path:/var/lib/mysql/data argument. This will be the MySQL
If the database directory is not initialized, the entrypoint script will first
and setup necessary database users and passwords. After the database is initialized,
or if it was already present,
mysqld is executed and will run as PID 1. You can
stop the detached container by running
docker stop mariadb_database.
When the MySQL image is run with the
--memory parameter set and you didn't
specify value for some parameters, their values will be automatically
calculated based on the available memory.
|Variable name||Configuration parameter||Relative value|
MySQL root user
The root user has no password set by default, only allowing local connections.
You can set it by setting the
MYSQL_ROOT_PASSWORD environment variable. This
will allow you to login to the root account remotely. Local connections will
still not require a password.
To disable remote root access, simply unset
MYSQL_ROOT_PASSWORD and restart
Since passwords are part of the image configuration, the only supported method
to change passwords for the database user (
MYSQL_USER) and root user is by
changing the environment variables
Changing database passwords through SQL statements or any way other than through
the environment variables aforementioned will cause a mismatch between the
values stored in the variables and the actual passwords. Whenever a database
container starts it will reset the passwords to the values stored in the
Default my.cnf file
With environment variables we are able to customize a lot of different parameters
or configurations for the mysql bootstrap configurations. If you'd prefer to use
your own configuration file, you can override the
variable with the full path of the file you wish to use. For example, the default
/etc/my.cnf but you can change it to
/etc/mysql/my.cnf by setting
Changing the replication binlog_format
Some applications may wish to use
row binlog_formats (for example, those built
with change-data-capture in mind). The default replication/binlog format is
statement but to change it you can set the
variable. For example
MYSQL_BINLOG_FORMAT=row. Now when you run the database
master replication turned on (ie, set the Docker/container
cmd to be
run-mysqld-master) the binlog will emit the actual data for the rows that change
as opposed to the statements (ie, DML like insert...) that caused the change.
This repository also provides tests (based on MTF) which checks basic functionality of the MariaDB image.
Run the tests using Makefile :
$ make test