Sign inSign up

ergomentum/mariadb

By ergomentum

•Updated almost 9 years ago

Ergomentum MariaDB

Image
0

2.0K

ergomentum/mariadb repository overview

Docker Image Stars Docker Image Pulls

⁠Ergomentum MariaDB

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:

  • Physical backup
  • Logical backup

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.

⁠Volumes

/docker-entrypoint-initdb.d
Files for database initialization (see above).

⁠Environment Variables

Warning: 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
Mandatory to start the database container first time with an empty directory /var/lib/mysql.
MYSQL_DATABASE
Optional database name used to create a new database if not exists. If not set MYSQL_USER will be used as default.
MYSQL_USER
Optional database user used to create a new database.
MYSQL_PASSWORD
Mandatory if MYSQL_USER is set.

⁠Exposed Ports

3306
The MySQL default port.

⁠Usage

Is is not necessary to use this image as base image. Simply create a container from it.

⁠Create a named volume to store database files

It's recommended to store store database files in a named volume.

docker \
  volume \
  create \
  --name mydbdata
⁠Start daemonized MySQL server with public port binding creating no new databases
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
⁠Start daemonized MySQL server with custom network to be used from another container
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.

⁠Get inside a running 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
⁠View Logs
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
⁠Backup
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"
⁠Restore
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

⁠Contributing

To contribute a feature or a bugfix please open a pull request⁠ on GitHub⁠.

See CONTRIBUTING⁠ for details.

⁠License

See the LICENSE⁠ file for license rights and limitations (Apache License, Version 2.0).

⁠References

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/⁠

Tag summary

Content type

Image

Digest

Size

111.2 MB

Last updated

almost 9 years ago

docker pull ergomentum/mariadb