A lightweight MariaDB container based on Alpine Linux, optimized for production deployments with multi-architecture support.
- Base Image: Alpine Linux 3.20.2
- Database Engine: MariaDB 10.11.8
- Image Size: Optimized for minimal footprint
- Default Character Set: utf8mb4
- Default Collation: utf8mb4_general_ci
amd64
/x86_64
: 64-bit Intel/AMDarm64v8
/aarch64
: 64-bit ARM (ARMv8)arm32v7
/armhf
: 32-bit ARM (ARMv7)
/var/lib/mysql
: Database files and data persistence/var/lib/mysql/mysql-bin
: Binary logs/etc/my.cnf.d/
: Custom configuration files
3306
: Default MariaDB port (TCP)
MYSQL_ROOT_PASSWORD
: Root user passwordMYSQL_DATABASE
: Name of the default databaseMYSQL_USER
: Application user usernameMYSQL_PASSWORD
: Application user password
MYSQL_CHARSET
: Database character set (default: utf8mb4)MYSQL_COLLATION
: Database collation (default: utf8mb4_general_ci)
docker run -d \
--name mariadb \
-p 3306:3306 \
-v mariadb_data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secure_root_password \
-e MYSQL_DATABASE=appdb \
-e MYSQL_USER=appuser \
-e MYSQL_PASSWORD=secure_user_password \
hhftechnology/alpine-mariadb:latest
version: '3.8'
services:
mariadb:
image: hhftechnology/alpine-mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_CHARSET: utf8mb4
MYSQL_COLLATION: utf8mb4_general_ci
volumes:
- mariadb_data:/var/lib/mysql
- ./custom.cnf:/etc/my.cnf.d/custom.cnf:ro
ports:
- "3306:3306"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
volumes:
mariadb_data:
driver: local
# Create required secrets
echo "secure_root_password" | docker secret create MYSQL_ROOT_PASSWORD -
echo "appdb" | docker secret create MYSQL_DATABASE -
echo "appuser" | docker secret create MYSQL_USER -
echo "secure_user_password" | docker secret create MYSQL_PASSWORD -
# Deploy the service
docker service create \
--name mariadb \
--secret MYSQL_ROOT_PASSWORD \
--secret MYSQL_DATABASE \
--secret MYSQL_USER \
--secret MYSQL_PASSWORD \
--mount type=volume,source=mariadb_data,target=/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD_FILE=/run/secrets/MYSQL_ROOT_PASSWORD \
-e MYSQL_DATABASE_FILE=/run/secrets/MYSQL_DATABASE \
-e MYSQL_USER_FILE=/run/secrets/MYSQL_USER \
-e MYSQL_PASSWORD_FILE=/run/secrets/MYSQL_PASSWORD \
--replicas 1 \
hhftechnology/alpine-mariadb:latest
Add custom InnoDB settings in /etc/my.cnf.d/mariadb-server.cnf
:
[mysqld]
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
[mysqld]
max_connections = 500
thread_cache_size = 128
The container automatically executes the following during first startup:
.sh
scripts in/docker-entrypoint-initdb.d/
.sql
files in/docker-entrypoint-initdb.d/
.sql.gz
files in/docker-entrypoint-initdb.d/
Files are executed in alphabetical order.
docker exec mariadb \
mysqldump -u root -p${MYSQL_ROOT_PASSWORD} \
--all-databases --single-transaction \
| gzip > backup_$(date +%Y%m%d).sql.gz
gunzip < backup.sql.gz | docker exec -i mariadb \
mysql -u root -p${MYSQL_ROOT_PASSWORD}
Supports all MariaDB character sets and collations. To change defaults:
docker run -d \
--name mariadb \
-e MYSQL_ROOT_PASSWORD=secure_password \
hhftechnology/alpine-mariadb:latest \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
- Always use secrets management in production
- Regularly update to the latest version
- Use custom configuration to disable unused features
- Implement network security policies
- Regular backup scheduling
- Monitor binary logs
- Use SSL for remote connections
- Container logs:
docker logs mariadb
- MariaDB error log:
/var/lib/mysql/error.log
- Slow query log:
/var/lib/mysql/slow-query.log
- Binary logs:
/var/lib/mysql/mysql-bin.*
- Issues: GitHub Issues
- Forum: HHF Technology Forum
- Contribute: Submit PRs to our GitHub repository
This project is licensed under the MIT License - see the LICENSE file for details.