Provides a MariaDB image based on the Ergomentum CentOS image.
MariaDB can be considered as a drop-in replacement for MySQL.
Since a database deals inevitably with data persistence whereas container are feasible stateless we have to manage this. The recommended approach for this are named volumes.
Because "multiple containers writing to a single shared volume can cause data corruption" [1] each data container should not be used by more than one database container. Using more than one databases you have to made the trade-off between one database container with multiple databases vs. multiple database containers with one database each. The former needs lowest resources but violates the tightly coupling of the containers. The later ensures the tightly coupling but multiplies the resource requirements. This image supports both scenarios.
Another decision is how to initialize your databases. You must at least provide the MySQL root user password as an
environment variable starting a container from this image the first time (assuming an empty
directory /var/lib/mysql for the database files). You may create a MySQL non root user at the same time and initialize
a database with additional environment variables. If you use your database container for more than one database you have
to start your database container one time for each database. Finally you may want to restart your database container one
more time skipping the MySQL root password in the environment variables for security reasons.
Additionally you can place any number of SQL files in the volume /docker-entrypoint-initdb.d to initialize your
database. Each filename must end with .sql Each statement must be on a single line. Or you can connect with the MySQL root user to
the running database container to initialize additional databases.
To backup your database you have to options:
For a physical backup you have top stop your database service to ensure a consistent state for all database files. Then
you can copy all files from /var/lib/mysql.
For a logical backup you leave your database service running and run commands below.
Notice: There is no chance to do a hot backup like Percona XtraBackup running only one process per container.
/docker-entrypoint-initdb.dWarning: Keep in mind "that all environment variables originating from Docker within a container are made available to any container that links to it. This could have serious security implications if sensitive data is stored in them." [2] As a consequence it is strictly recommended to prefer a user defined network to legacy container links for maximum isolation.
MYSQL_ROOT_PASSWORD/var/lib/mysql.MYSQL_DATABASEMYSQL_USER will be
used as default.MYSQL_USERMYSQL_PASSWORDMYSQL_USER is set.3306Is is not necessary to use this image as base image. Simply create a container from it.
It's recommended to store store database files in a named volume.
docker \
volume \
create \
--name mydbdata
docker \
volume \
create \
--name mydbdata
docker \
run \
-d \
-e MYSQL_ROOT_PASSWORD=secret \
-p 3306:3306 \
-v mydbdata:/var/lib/mysql \
ergomentum/mariadb
This allows you to connect with any mysql client to initialize the database:
mysql -hip_of_your_docker_host -uroot -psecret
docker \
volume \
create \
--name mydbdata
docker \
network \
create \
--driver bridge \
mynetwork
docker \
run \
-d \
-e MYSQL_ROOT_PASSWORD=secret \
-p 3306:3306 \
-v mydbdata:/var/lib/mysql \
--net=mynetwork \
--name=mydbservice \
ergomentum/mariadb
docker \
run \
--rm \
-ti \
--net=mynetwork \
ergomentum/mariadb
Notice: There is no container linking used. There are no environment variable from the database container exposed. You must know the credentials to connect to the database container.
docker \
volume \
create \
--name mydbdata
docker \
run \
-d \
-e MYSQL_ROOT_PASSWORD=secret \
-p 3306:3306 \
-v mydbdata:/var/lib/mysql \
--name=mydbservice \
ergomentum/mariadb
docker \
exec \
-it \
mydbservice \
bash
docker \
volume \
create \
--name mydbdata
docker \
run \
-d \
-e MYSQL_ROOT_PASSWORD=secret \
-p 3306:3306 \
-v mydbdata:/var/lib/mysql \
--name=mydbservice \
ergomentum/mariadb
docker \
logs \
mydbservice
docker \
volume \
create \
--name mydbdata
docker \
network \
create \
--driver bridge \
mynetwork
docker \
run \
-d \
-e MYSQL_ROOT_PASSWORD=secret \
-p 3306:3306 \
-v mydbdata:/var/lib/mysql \
--net=mynetwork \
--name=mydbservice \
ergomentum/mariadb
docker \
run \
--rm \
-it \
--net=mynetwork \
ergomentum/mariadb
mysqldump -hmydbservice -uroot -psecret --single-transaction --all-databases \
> "mydbservice_$(date -u +'%y-%m-%d_%H-%M-%S').sql"
docker \
stop \
mydbservice
docker \
run \
-d \
-e MYSQL_ROOT_PASSWORD=secret \
--net=mynetwork \
--name=mydbservice2 \
ergomentum/mariadb
docker \
run \
--rm \
-i \
--net=mynetwork \
ergomentum/mariadb
mysql -hmydbservice2 -uroot -psecret < *.sql
To contribute a feature or a bugfix please open a pull request on GitHub.
See CONTRIBUTING for details.
See the LICENSE file for license rights and limitations (Apache License, Version 2.0).
1. https://docs.docker.com/engine/userguide/containers/dockervolumes/#important-tips-on-using-shared-volumes
2. https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/
Content type
Image
Digest
Size
111.2 MB
Last updated
almost 9 years ago
docker pull ergomentum/mariadb