Skip to content

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

Notifications You must be signed in to change notification settings

ServerContainers/mysql

Repository files navigation

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

mysql/mariadb on alpine with backup scheduler and restore mechanism

What is it

This Dockerfile (ghcr.io/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 GitHub Registry ghcr.io/servercontainers/mysql

View in GitHub ServerContainers/mysql

currently tested on: x86_64, arm64, arm

IMPORTANT!

In March 2023 - Docker informed me that they are going to remove my organizations servercontainers and desktopcontainers unless I'm upgrading to a pro plan.

I'm not going to do that. It's more of a professionally done hobby then a professional job I'm earning money with.

In order to avoid bad actors taking over my org. names and publishing potenial backdoored containers, I'd recommend to switch over to my new github registry: ghcr.io/servercontainers.

Build & Versions

You can specify DOCKER_REGISTRY environment variable (for example my.registry.tld) and use the build script to build the main container and it's variants for x86_64, arm64 and arm

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).

To build a latest tag run ./build.sh release

Changelogs

  • 2023-03-20
    • github action to build container
    • implemented ghcr.io as new registry
  • 2023-03-19
    • switched from docker hub to a build-yourself container
  • 2023-01-19
    • fixed restore code
  • 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

Quickstart (recommended)

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)

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages