On AlmaLinux 8 systems, MariaDB is commonly installed by default, especially when using hosting control panels such as Webmin or cPanel. In scenarios such as application testing, version compatibility checks, or database migration, it is often necessary to run MySQL 8 in parallel with an existing MariaDB installation.
Replacing MariaDB with MySQL is not recommended on production systems due to package conflicts and dependency risks.
A safer and fully isolated approach is to deploy MySQL 8 using Docker containers.
This document describes how to install Docker on AlmaLinux 8 and run MySQL 8 in a container while keeping MariaDB fully operational on the host system.
Running applications that explicitly require MySQL 8
Testing MySQL-specific features not available in MariaDB
Migration testing between MariaDB and MySQL
Development and staging environments
Avoiding RPM-level database conflicts
AlmaLinux 8 server
MariaDB already installed and running
Root or sudo access
SSH access to the server
Basic familiarity with Linux command-line operations
Before proceeding, confirm that MariaDB is active and listening on its default port.
systemctl status mariadb
This confirms that the MariaDB service is running and not reporting startup errors.
mariadb --version
This command displays the installed MariaDB client version.
sudo ss -tulpn | grep 3306
MariaDB should be listening on TCP port 3306.
MySQL 8 will be configured to use a different port to avoid conflicts.
Ensure the system is fully up to date.
sudo dnf update -y
Install required dependencies used by Docker:
sudo dnf install -y yum-utils device-mapper-persistent-data lvm2
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
AlmaLinux is binary-compatible with CentOS, so the CentOS Docker repository is used.
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
This installs Docker Engine, client utilities, container runtime, and Compose support.
sudo systemctl enable docker
sudo systemctl start docker
Enables Docker at system boot
Starts the Docker daemon immediately
docker run hello-world
Successful execution confirms Docker is functioning correctly.
Docker volumes ensure database data persists across container restarts or recreation.
docker volume create mysql8_data
Verify volume creation:
docker volume ls
Download the official MySQL 8 image from Docker Hub.
docker pull mysql:8.0
Verify the image is available locally:
docker images | grep mysql
MariaDB occupies port 3306, therefore MySQL 8 will be exposed on 3307.
docker run -d \
--name mysql8-container \
--restart unless-stopped \
-p 3307:3306 \
-v mysql8_data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=StrongRootPassword123! \
-e MYSQL_DATABASE=default_db \
-e MYSQL_USER=app_user \
-e MYSQL_PASSWORD=StrongUserPassword123! \
mysql:8.0 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
-d
Runs the container in detached mode.
--name mysql8-container
Assigns a predictable container name.
--restart unless-stopped
Automatically restarts the container on reboot or failure.
-p 3307:3306
Maps host port 3307 to the container’s MySQL port.
-v mysql8_data:/var/lib/mysql
Stores MySQL data in a persistent Docker volume.
MYSQL_ROOT_PASSWORD
Sets the MySQL root password.
MYSQL_DATABASE
Creates an initial database.
MYSQL_USER and MYSQL_PASSWORD
Creates a non-root database user.
UTF8MB4 settings
Enable full Unicode support.
docker ps
The output should show mysql8-container in a running state.
docker logs mysql8-container
Successful initialization ends with:
MySQL init process done. Ready for start up.
docker exec -it mysql8-container mysql -u root -p
Run validation queries:
SHOW DATABASES;
SELECT VERSION();
EXIT;
Install the MySQL client if not present:
sudo dnf install -y mysql
Connect using the mapped port:
mysql -h 127.0.0.1 -P 3307 -u root -p
If firewalld is enabled, allow access to port 3307.
sudo firewall-cmd --state
Add firewall rule:
sudo firewall-cmd --permanent --add-port=3307/tcp
sudo firewall-cmd --reload
Verify open ports:
sudo firewall-cmd --list-ports
Webmin can manage both databases independently.
MariaDB: localhost:3306
MySQL 8 (Docker): localhost:3307
Add MySQL 8 under:
Webmin → Un-used Modules → MySQL Database Server
docker exec mysql8-container mysqldump -u root -pStrongRootPassword123! --all-databases > mysql8_backup.sql
docker exec -i mysql8-container mysql -u root -pStrongRootPassword123! < mysql8_backup.sql
docker start mysql8-container
docker stop mysql8-container
docker restart mysql8-container
docker stats mysql8-container
docker inspect mysql8-container
Do not use the MySQL root account for applications
Restrict database access using firewall rules
Use strong passwords and rotate them regularly
Keep Docker images updated
docker pull mysql:8.0
By deploying MySQL 8 inside Docker, it is possible to run MySQL and MariaDB simultaneously on AlmaLinux 8 without conflicts.
This approach provides:
Complete isolation between database engines
No impact on existing MariaDB services
Persistent storage and easy backups
Simplified upgrades and rollback
This configuration is suitable for development, testing, and controlled production scenarios where MySQL 8 is required.