An open API service indexing awesome lists of open source software.

https://github.com/hhftechnology/alpine-mariadb

MariaDB running on Alpine Linux [Docker]
https://github.com/hhftechnology/alpine-mariadb

Last synced: 5 months ago
JSON representation

MariaDB running on Alpine Linux [Docker]

Awesome Lists containing this project

README

          

# Alpine MariaDB Container

[![Docker Automated build](https://img.shields.io/docker/automated/hhftechnology/alpine-mariadb.svg?style=for-the-badge&logo=docker)](https://hub.docker.com/r/hhftechnology/alpine-mariadb/)
[![Docker Pulls](https://img.shields.io/docker/pulls/hhftechnology/alpine-mariadb.svg?style=for-the-badge&logo=docker)](https://hub.docker.com/r/hhftechnology/alpine-mariadb/)
[![Alpine Version](https://img.shields.io/badge/Alpine%20version-v3.20.2-green.svg?style=for-the-badge&logo=alpine-linux)](https://alpinelinux.org/)
[![MariaDB Version](https://img.shields.io/badge/Mariadb%20version-v10.11.8-green.svg?style=for-the-badge&logo=mariadb)](https://mariadb.org/)

[![Build ad Deploy Alpine MariaDB](https://github.com/hhftechnology/alpine-mariadb/actions/workflows/main.yml/badge.svg)](https://github.com/hhftechnology/alpine-mariadb/actions/workflows/main.yml)

A lightweight MariaDB container based on Alpine Linux, optimized for production deployments with multi-architecture support.

## Technical Specifications

- **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

## Supported Architectures

- `amd64`/`x86_64`: 64-bit Intel/AMD
- `arm64v8`/`aarch64`: 64-bit ARM (ARMv8)
- `arm32v7`/`armhf`: 32-bit ARM (ARMv7)

## Container Configuration

### Volume Mount Points
- `/var/lib/mysql`: Database files and data persistence
- `/var/lib/mysql/mysql-bin`: Binary logs
- `/etc/my.cnf.d/`: Custom configuration files

### Network Ports
- `3306`: Default MariaDB port (TCP)

### Environment Variables

#### Required Variables
- `MYSQL_ROOT_PASSWORD`: Root user password
- `MYSQL_DATABASE`: Name of the default database
- `MYSQL_USER`: Application user username
- `MYSQL_PASSWORD`: Application user password

#### Optional Variables
- `MYSQL_CHARSET`: Database character set (default: utf8mb4)
- `MYSQL_COLLATION`: Database collation (default: utf8mb4_general_ci)

## Deployment Examples

### Basic Docker Run
```bash
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
```

### Docker Compose Configuration
```yaml
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
```

### Docker Swarm Deployment
```bash
# 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
```

## Performance Tuning

### InnoDB Configuration
Add custom InnoDB settings in `/etc/my.cnf.d/mariadb-server.cnf`:

```ini
[mysqld]
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
```

### Connection Pool Settings
```ini
[mysqld]
max_connections = 500
thread_cache_size = 128
```

## Database Initialization

The container automatically executes the following during first startup:
1. `.sh` scripts in `/docker-entrypoint-initdb.d/`
2. `.sql` files in `/docker-entrypoint-initdb.d/`
3. `.sql.gz` files in `/docker-entrypoint-initdb.d/`

Files are executed in alphabetical order.

## Backup and Restore

### Backup
```bash
docker exec mariadb \
mysqldump -u root -p${MYSQL_ROOT_PASSWORD} \
--all-databases --single-transaction \
| gzip > backup_$(date +%Y%m%d).sql.gz
```

### Restore
```bash
gunzip < backup.sql.gz | docker exec -i mariadb \
mysql -u root -p${MYSQL_ROOT_PASSWORD}
```

## Character Set Support

Supports all MariaDB character sets and collations. To change defaults:

```bash
docker run -d \
--name mariadb \
-e MYSQL_ROOT_PASSWORD=secure_password \
hhftechnology/alpine-mariadb:latest \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
```

## Security Considerations

1. Always use secrets management in production
2. Regularly update to the latest version
3. Use custom configuration to disable unused features
4. Implement network security policies
5. Regular backup scheduling
6. Monitor binary logs
7. Use SSL for remote connections

## Monitoring & Logging

- 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.*`

## Support & Contributing

- Issues: [GitHub Issues](https://github.com/hhftechnology/alpine-mariadb/issues)
- Forum: [HHF Technology Forum](https://forum.hhf.technology)
- Contribute: Submit PRs to our [GitHub repository](https://github.com/hhftechnology/alpine-mariadb)

## License

This project is licensed under the MIT License - see the LICENSE file for details.