MariaDB 11.4.10 on Alpine Linux
1.4K
A lightweight MariaDB Docker image built on top of Alpine Linux,
inspired by yobasystems/alpine-mariadb.
For the official MariaDB image maintained by the MariaDB developer community, see hub.docker.com/_/mariadb.
Compatible with 32-bit SOC boards, such as Raspberry Pi 3, Orange Pi PC, etc.
| Docker Hub | hub.docker.com/r/44934045/mariadb_alpine |
| Source Code | github.com/dantavares/docker-mariadb_alpine |
| Component | Version |
|---|---|
| Alpine Linux | latest (≥ 3.23.4) |
| MariaDB | latest (≥ 11.4.10) |
Key characteristics:
mysql user (uid=1000, gid=1000 by default — both adjustable via environment variables).| Mount path | Purpose |
|---|---|
/var/lib/mysql | Database data files |
/etc/my.cnf.d | Configuration files and X.509 certificates |
| Variable | Required | Default | Description |
|---|---|---|---|
MYSQL_ROOT_PASSWORD | No | (random) | Root password. If omitted on a fresh install, a random password is generated and printed to the log. |
MYSQL_DATABASE | No | — | Name of the database to create on first boot. |
MYSQL_USER | No | — | Application user granted full access to MYSQL_DATABASE. Requires MYSQL_DATABASE to be set. |
MYSQL_PASSWORD | No | — | Password for MYSQL_USER. |
MYSQL_CHARSET | No | utf8 | Default character set for the created database. |
MYSQL_COLLATION | No | utf8_general_ci | Default collation for the created database. |
PUID | No | 1000 | UID to run the mysql service user as. |
PGID | No | 1000 | GID to run the mysql service user as. |
TZ | No | UTC | Container timezone (e.g. America/Sao_Paulo). |
VERBOSE | No | 0 | Set to 1 for more detailed startup logs. |
Note:
MYSQL_USERis only created whenMYSQL_DATABASEis also defined.
All variables that affect database creation are evaluated only on the first boot, when/var/lib/mysql/mysqldoes not yet exist.
On the first boot only, any files placed in /docker-entrypoint-initdb.d/ are automatically executed
after the initial database setup, in alphabetical order. Supported file types:
| Extension | Behaviour |
|---|---|
.sh | Executed as a shell script. Has full access to all container environment variables. |
.sql | Imported directly into MariaDB. |
.sql.gz | Decompressed on the fly and imported into MariaDB. |
Files with any other extension are silently ignored.
How it works internally:
/docker-entrypoint-initdb.d/ is processed in order.If MYSQL_DATABASE is defined, SQL scripts are executed with that database pre-selected — useful for dumps
that do not contain a USE <database>; statement.
Example — mounting an init directory:
docker run -d \
--name mariadb \
--stop-timeout 60 \
-e MYSQL_ROOT_PASSWORD="Hard2Gue$$Password" \
-e MYSQL_DATABASE=myapp \
-e MYSQL_USER=myuser \
-e MYSQL_PASSWORD=mypassword \
-v /your_data_dir:/var/lib/mysql \
-v /your_init_dir:/docker-entrypoint-initdb.d \
-p 3306:3306 \
44934045/mariadb_alpine
Files inside
/docker-entrypoint-initdb.d/are only executed once.
On subsequent container starts the directory is ignored because the data volume already exists.
docker run -d \
--name mariadb \
--stop-timeout 60 \
-e VERBOSE=1 \
-e MYSQL_ROOT_PASSWORD="Hard2Gue$$Password" \
-e MYSQL_DATABASE=myapp \
-e MYSQL_USER=myuser \
-e MYSQL_PASSWORD=mypassword \
-v /your_data_dir:/var/lib/mysql \
-p 3306:3306 \
44934045/mariadb_alpine
docker run -d \
--name mariadb \
--stop-timeout 60 \
-e VERBOSE=1 \
-v /your_config_dir:/etc/my.cnf.d \
-v /your_data_dir:/var/lib/mysql \
-p 3306:3306 \
44934045/mariadb_alpine
docker exec -it mariadb mariadb -u root -p
docker cp mariadb:/etc/my.cnf.d/* ./config/
services:
mariadb:
image: 44934045/mariadb_alpine
container_name: mariadb
restart: unless-stopped
stop_grace_period: 60s # required for clean InnoDB shutdown
ports:
- "127.0.0.1:3306:3306"
volumes:
- db-data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
MYSQL_ROOT_PASSWORD: yourpassword
MYSQL_DATABASE: myapp
MYSQL_USER: myuser
MYSQL_PASSWORD: mypassword
TZ: America/Sao_Paulo
volumes:
db-data:
Important:
stop_grace_period: 60sis required to allow InnoDB to flush data to disk before the container is forcibly killed. Without it, Docker's default 10-second timeout may cause an abrupt shutdown, resulting in a crash recovery (Recovering after a crash using tc.log) on the next startup. This setting cannot be embedded in the image itself and must always be defined at the orchestration level.
apiVersion: v1
kind: Pod
metadata:
name: mariadb
namespace: default
labels:
app: mariadb
purpose: database
spec:
terminationGracePeriodSeconds: 60 # required for clean InnoDB shutdown
volumes:
- name: maria-conf
hostPath:
path: /data/mariadb/conf
- name: maria-data
hostPath:
path: /data/mariadb/db
containers:
- name: mariadb
image: 44934045/mariadb_alpine
env:
- name: VERBOSE
value: "1"
- name: MYSQL_ROOT_PASSWORD
value: "Hard2Gue$$Password"
- name: MYSQL_DATABASE
value: myapp
- name: MYSQL_USER
value: myuser
- name: MYSQL_PASSWORD
value: mypassword
volumeMounts:
- name: maria-conf
mountPath: /etc/my.cnf.d
- name: maria-data
mountPath: /var/lib/mysql
ports:
- containerPort: 3306
protocol: TCP
Copy your certificate and key files into the configuration volume (e.g. /data/mariadb/conf) and add the
following to a file named server.cnf in that directory:
[server]
ssl=on
ssl-ca=/etc/my.cnf.d/ca-chain.pem
ssl-cert=/etc/my.cnf.d/server.crt
ssl-key=/etc/my.cnf.d/server.key
Connect a client over TLS:
mariadb -h <host> --ssl -u root -p
Verify the connection and cipher in use:
MariaDB [(none)]> STATUS;
-- Look for a line such as:
-- SSL: Cipher in use is TLS_AES_256_GCM_SHA384
For more information, refer to the MariaDB Secure Connections documentation.
mariadb-dumpexport MYSQL_ROOT_PASSWORD="Hard2Gue$$Password"
docker exec mariadb sh -c \
"exec mariadb-dump --all-databases -uroot -p\"$MYSQL_ROOT_PASSWORD\"" \
> /backup/all_databases.sql
To back up a single database:
docker exec mariadb sh -c \
"exec mariadb-dump myapp -uroot -p\"$MYSQL_ROOT_PASSWORD\"" \
> /backup/myapp.sql
export MYSQL_ROOT_PASSWORD="Hard2Gue$$Password"
docker exec -i mariadb sh -c \
"exec mariadb -uroot -p\"$MYSQL_ROOT_PASSWORD\"" \
< /backup/all_databases.sql
Upgrading between major MariaDB versions can be complex. Always read the official upgrade documentation first.
As a general guideline:
mariadb-upgrade to update the system tables:export MYSQL_ROOT_PASSWORD="Hard2Gue$$Password"
docker exec -it mariadb sh -c \
"exec mariadb-upgrade -uroot -p\"$MYSQL_ROOT_PASSWORD\""
This project is provided as-is under the GNU GENERAL PUBLIC LICENSE.
Content type
Image
Digest
sha256:ed203a82d…
Size
78.4 MB
Last updated
5 months ago
docker pull 44934045/mariadb_alpine