Adding Multiple Database Servers in Plesk Using Docker


Adding Multiple Database Servers in Plesk Using Docker

By default, you can only install a single version of MySQL/MariaDB on your server. However, if some of your customer require a different MySQL version, you can use docker. Plesk allows you to add multiple database servers using its Docker extension. This is particularly useful when hosting multiple applications requiring different database versions. In this guide, we will walk through installing and configuring a MariaDB 10.11 Docker container, mapping its ports, and adding it to Plesk as an external database server.

Step 1: Prepare the Server

  1. Log into your server via SSH.
  2. Create a directory for the Docker container’s data storage to ensure persistence:
    mkdir -p /var/docker/mysql/

Step 2: Install and Configure Docker in Plesk

  1. Log in to Plesk.
  2. Navigate to Extensions and ensure the Docker extension is installed. If not, install it.
  3. Go to Docker in Plesk.
  4. In the search box, type mariadb and press Enter.
  5. Select the MariaDB image and choose version 10.11.
  6. Click Next.
  7. Configure the container:
    • Check Automatic start after system reboot.
    • Uncheck Automatic port mapping and manually map:
      • Internal port 3306 to external port 3307.
    • Ensure firewall rules allow traffic on ports 3307 and 33070.
    • Set Volume mapping:
      • Container: /var/lib/mysql
      • Host: /var/docker/mysql
      • Warning: Not mapping this can result in data loss when the container is recreated.
    • Add an environment variable MYSQL_ROOT_PASSWORD and specify a secure root password.
    • Click Run to start the container.

Step 3: Add the MySQL Docker Container as an External Database in Plesk

Once the container is running, we need to add it to Plesk as an external database server:

  1. Log in to Plesk.
  2. Navigate to Tools & Settings > Database Servers (under Applications & Databases).
  3. Click Add Database Server.
  4. Configure the database server:
    • Database server type: Select MariaDB.
    • Hostname or IP Address: Use 127.0.0.1.
    • Port: Enter 3307 (as mapped earlier).
    • Set as Default (Optional): Check Use this server as default for MySQL if you want clients to use this server by default.
    • Credentials: Enter the root user and password specified during container setup.
    • Click OK to save the configuration.

Step 4: Using the New Database Server

Now that the new database server is added, clients can choose it when creating a new database in Plesk:

  1. Go to Databases in Plesk.
  2. Click Add Database.
  3. Under Database server, select the newly added MariaDB 10.11 instance.

This setup allows clients to choose different database servers for their applications while ensuring database persistence and security.

Conclusion

By leveraging Docker, you can efficiently manage multiple database versions on a Plesk server. This method ensures better isolation, easier upgrades, and avoids conflicts between database versions, providing a flexible and robust hosting environment.