Sign inSign up

krautsalad/mariadb

By krautsalad

•Updated 4 months ago

MariaDB with memory tuning, optional slow-query logging, and scheduled table optimization.

Image
Databases & storage
1

1.6K

krautsalad/mariadb repository overview

⁠docker-mariadb

MariaDB with memory tuning, optional slow-query logging, and scheduled table optimization.

docker-mariadb extends the official MariaDB Docker image⁠. At startup it generates a tuned my.cnf from environment variables, runs MariaDB under supervisord together with cron, and can schedule mariadb-check --optimize jobs.

⁠Configuration

⁠Docker Compose Example
# docker-compose.yml
services:
  mariadb:
    container_name: mariadb
    environment:
      LONG_QUERY_TIME: 3
      MARIADB_AUTO_UPGRADE: true
      MARIADB_DATABASE: example
      MARIADB_PASSWORD: VerySecurePassword
      MARIADB_ROOT_PASSWORD: VerySecurePassword
      MARIADB_USER: example
      MEMORY_GB: 2
      OPTIMIZE_ENABLED: 1
      OPTIMIZE_SCHEDULE: 0 1 * * 6
      SLOW_QUERY_LOG: 1
      TZ: Europe/Berlin
    healthcheck:
      interval: 30s
      retries: 10
      start_period: 10s
      test: [ "CMD", "healthcheck.sh", "--connect", "--innodb_initialized", "--mariadbupgrade" ]
      timeout: 10s
    image: krautsalad/mariadb
    ports:
      - "3306:3306"
    restart: unless-stopped
    security_opt:
      - seccomp:unconfined
    volumes:
      - ./mariadb-config/my.cnf:/etc/mysql/conf.d/zz-overrides.cnf:ro
      - ./mariadb-logs:/var/log/mysql
      - ./mariadb-data:/var/lib/mysql
⁠Environment Variables
⁠Image-specific
VariableDefaultDescription
LONG_QUERY_TIME3Queries running longer than this many seconds are logged when slow query logging is enabled.
MEMORY_GB0.5Memory budget for the database in gigabytes.
OPTIMIZE_ENABLED0Enables the cron job which reorganizes table storage and indexes to reduce fragmentation and reclaim unused space.
OPTIMIZE_SCHEDULE0 1 * * 6Cron expression for the optimize job (default: Saturday at 01:00). Only used when the cron job is enabled.
SLOW_QUERY_LOG0Enables slow query logging.
⁠Official

This image supports the upstream variables. Common ones:

VariableDefaultDescription
MARIADB_AUTO_UPGRADE—Run mariadb-upgrade on start when needed.
MARIADB_DATABASE—Database created on first start.
MARIADB_PASSWORD—Password for MARIADB_USER.
MARIADB_ROOT_PASSWORD—Root password.
MARIADB_USER—Non-root user created on first start (used with MARIADB_PASSWORD).
TZUTCTimezone for logs and cron.

See the official documentation⁠ for the full list.

⁠How it works

At container start, the custom entrypoint reads the tuning variables, substitutes placeholders in my.cnf.template, and writes /etc/mysql/conf.d/zz-overrides-initial.cnf. You can optionally override MariaDB settings further by mounting a custom my.cnf to /etc/mysql/conf.d/zz-overrides.cnf, as in the Docker Compose example above. If OPTIMIZE_ENABLED is on, it installs a cron file at /etc/cron.d/mariadb-optimize.

Supervisord then starts MariaDB (via the official image entrypoint) and crond for scheduled jobs. Database files are stored under /var/lib/mysql; mount a volume there to persist data.

⁠Source Code

You can find the full source code on GitHub⁠.

Tag summary

Content type

Image

Digest

sha256:f34a07b47…

Size

120.7 MB

Last updated

4 months ago

docker pull krautsalad/mariadb