MariaDB: use Docker Compose for MariaDB
Here's an easy way how to set up MariaDB using Docker Compose

If you want to use MariaDB within your Docker environment, the easiest way is to use Docker Compose. Here's a simple `docker-compose.yml':
services:
db:
image: mariadb
ports:
- 3306:3306
environment:
- MARIADB_ROOT_PASSWORD=XxXxXxXx
Instead of using MARIADB_ROOT_PASSWORD
, you could also use:
MARIADB_ROOT_PASSWORD_HASH
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD
MARIADB_RANDOM_ROOT_PASSWORD
Let's pull the image and start the container:
# docker compose pull
# docker compose up -d
[+] Pulling 9/9
✔ db Pulled 4.2s
✔ 49b96e96358d Already exists 0.0s
✔ 1d2634dd6770 Pull complete 0.4s
✔ d52437edb690 Pull complete 0.7s
✔ 1abcc7eca303 Pull complete 0.7s
✔ 48714b635922 Pull complete 0.7s
✔ b8c1a2d23fef Pull complete 2.5s
✔ 4fffdbfe6df8 Pull complete 2.6s
✔ ca3043bf49e2 Pull complete 2.6s
[+] Running 2/2
✔ Network mariadb_default Created 0.1s
✔ Container mariadb-db-1 Started
Let's have a look at the logs:
db-1 | 2025-04-15 13:56:58+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.7.2+maria~ubu2404 started.
db-1 | 2025-04-15 13:56:58+00:00 [Warn] [Entrypoint]: /sys/fs/cgroup///memory.pressure not writable, functionality unavailable to MariaDB
db-1 | 2025-04-15 13:56:58+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db-1 | 2025-04-15 13:56:58+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.7.2+maria~ubu2404 started.
db-1 | 2025-04-15 13:56:59+00:00 [Note] [Entrypoint]: Initializing database files
db-1 | 2025-04-15 13:56:59 0 [Warning] mariadbd: io_uring_queue_init() failed with errno 2
db-1 | 2025-04-15 13:56:59 0 [Warning] InnoDB: liburing disabled: falling back to innodb_use_native_aio=OFF
db-1 | 2025-04-15 13:57:01+00:00 [Note] [Entrypoint]: Database files initialized
db-1 | 2025-04-15 13:57:01+00:00 [Note] [Entrypoint]: Starting temporary server
db-1 | 2025-04-15 13:57:01+00:00 [Note] [Entrypoint]: Waiting for server startup
db-1 | 2025-04-15 13:57:01 0 [Note] Starting MariaDB 11.7.2-MariaDB-ubu2404 source revision 80067a69feaeb5df30abb1bfaf7d4e713ccbf027 server_uid M1Ysub1BDlKHQoyUdFdL1gn45UI= as process 92
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: Compressed tables use zlib 1.3
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: Number of transaction pools: 1
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: Using ARMv8 crc32 + pmull instructions
db-1 | 2025-04-15 13:57:01 0 [Warning] mariadbd: io_uring_queue_init() failed with errno 0
db-1 | 2025-04-15 13:57:01 0 [Warning] InnoDB: liburing disabled: falling back to innodb_use_native_aio=OFF
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: Completed initialization of buffer pool
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: File system buffers for log disabled (block size=4096 bytes)
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: End of log at LSN=47763
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: Opened 3 undo tablespaces
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: 128 rollback segments in 3 undo tablespaces are active.
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
db-1 | 2025-04-15 13:57:01 0 [Note] InnoDB: log sequence number 47763; transaction id 14
db-1 | 2025-04-15 13:57:01 0 [Note] Plugin 'FEEDBACK' is disabled.
db-1 | 2025-04-15 13:57:01 0 [Note] Plugin 'wsrep-provider' is disabled.
New, we can easily access the database from the console:
docker exec -ti mariadb-db-1 mariadb -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 11.7.2-MariaDB-ubu2404 mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Since we exploited the port 3306
, we can also connect to the database from another system:
# mariadb -u root -p -P 3306 -h <docker hostname>
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 11.7.2-MariaDB-ubu2404 mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Support MariaDB developers by giving a star at https://github.com/MariaDB/server
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
This also works when there's not the MariaDB, but the MySQL client:
# mysql -u root -p -P 3306 -h <docker hostname>
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 11.7.2-MariaDB-ubu2404 mariadb.org binary distribution
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
But keep in mind that MySQL and MariaDB are not fully compatible any more; newer MySQL and MariaDB will differ more than older ones. Also when using MariaDB specific features, the MySQL client will not support them.