Public | Automated Build

Last pushed: 8 months ago
Short Description
mysql mariadb docker container - alpine based with backup and restore functionality
Full Description

Docker MySQL/MariaDB-Server Container (servercontainers/mysql)

maintained by ServerContainers

FAQ - All you need to know about the servercontainers Containers

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:3.5 Image

View in Docker Registry servercontainers/mysql

View in GitHub ServerContainers/mysql

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)
Docker Pull Command
Owner
servercontainers
Source Repository