Sign inSign up

servercontainers/mysql

By servercontainers

Updated 2 months ago

mysql - (servercontainers/mysql) (+ optional backup scheduler / restore) on alpine [x86 + arm]

Image
1

4.1K

servercontainers/mysql repository overview

mysql/mariadb - (servercontainers/mysql) [x86 + arm]

mysql/mariadb on alpine with backup scheduler and restore mechanism

What is it

This Dockerfile (available as servercontainers/mysql) gives you a MySQL/MariaDB SQL-Server on alpine. It is also possible to configure an auto mysqldump and restore mechanism.

For Configuration of the Server you use environment Variables.

It's based on the alpine Image

View in Docker Registry servercontainers/mysql

View in GitHub ServerContainers/mysql

Versioning and Variants

You'll find all images tagged like a3.15.0-m10.6.4-r2 which means a<alpine version>-m<mysql/mariadb version>. This way you can pin your installation/configuration to a certian version. or easily roll back if you experience any problems (don't forget to open a issue in that case ;D).

The latest version will be updated/released after I managed to test a new pinned version in my production environment. This way I can easily find and fix bugs without affecting any users. It will result in a way more stable container.

Changelogs

  • 2022-01-31
    • rewrite and update, multi-arch build, versioning

Environment variables and defaults

MySQL Daemon

The daemon stores the database data beneath: /var/lib/mysql

  • ADMIN_USER
    • no default - needed only when backup enabled or for mysql initialisation
  • ADMIN_PASSWORD
    • no default - needed only when backup enabled or for mysql initialisation
Optional Backup & Restore

Backup/Restore is disabled by default!
In default it stores it's dumps beneath: /var/mysql-backup If you enable it the restore mechanism is automatically enabled too. In default it loads the restorable dumps from /var/mysql-backup/to_restore/*.sql

  • BACKUP_ENABLED
    • default not set - if set to any value it enables backup/restore functionality
  • BACKUP_REPETITION_TIME
    • default: 1h time the backup/restore will be rerun. can have an optional suffix of (s)econds, (m)inutes, (h)ours, or (d)ays
  • BACKUP_PATH
    • default: /var/mysql-backup - the place to store the mysqldumps
  • RESTORE_DISABLE
    • default not set - if set to any value it disables restore functionality
Optional DB & User auto-creation
  • DB_NAME
    • no default - required if you want the auto create a database with user
  • DB_USER
    • no default - required if you want the auto create a database with user
  • DB_PASSWORD
    • no default - required if you want the auto create a database with user

Using the servercontainers/mysql Container

Backups and restore

If you enabled the backup via environment variable, you get mysql dumps for each database, and one big sql dump containing all databases.

You can also use this to easily restore a single database. Just copy the sql dump to the backup folders subfolder to_restore with the databasename as filename and .sql as suffix.

for example: to_restore/nextcloud.sql will be imported as database nextcloud.

Running MySQL

The following example uses Docker Compose to start a example MySQL Server and a PhpMyAdmin Container

docker-compose up

After that just open https://localhost/ - ingore the self signed certificate warning and login with your mysql admin credentials admin / password.

Non persistent manual start

The following command starts a non persistent mysql database which will be lost after the container is deleted. (Great for testing!)

docker run -d --name mysql \
-e 'ADMIN_USER=dbadmin' -e 'ADMIN_PASSWORD=adminpw' \
-e 'DB_NAME=testdb' -e 'DB_USER=testdbuser' -e 'DB_PASSWORD=usersecret' \
servercontainers/mysql
Manual start

For the first start you'll need to provide the ADMIN_USER and ADMIN_PASSWORD variables

docker run -d --name mysql \
-e 'ADMIN_USER=dbadmin' -e 'ADMIN_PASSWORD=pa55worD!' \
-e 'BACKUP_ENABLED=enable' \
-p 3306:3306 \
-v /tmp/mysqldata:/var/lib/mysql \
-v /tmp/mysqlbackup:/var/mysql-backup \
servercontainers/mysql

you need to provide the admin credentials only if you start the container for the first time (so it can initialize a new Database) or if you use the internal mysqldump backup / restore mechanism

Connection example

Now you can connect to the MySQL Server via the normal mysql-client cli:

mysql -u $ADMIN_USER -p -h $(docker inspect --format='{{.NetworkSettings.IPAddress}}' $CONTAINER_ID)

Tag summary

Content type

Image

Digest

sha256:48bb6a0d7

Size

72.2 MB

Last updated

2 months ago

docker pull servercontainers/mysql