MariaDB is a SQL & NoSQL Relational database. it is used to store files for long-term use and is used in most containers we use that need to grow and store data. You can learn more about MariaDB from the links below:
MariaDB is an open-source community-developed fork of MySQL. MySQL (released 1995) has been around much longer than Mariadb (released 2009). MariaDB handles overall performance and larger files better than MySQL and offers more features than MySQL as well. We use both MySQL and MariaDB but always prefer to use MariaDB for its performance increase and feature set.
We are going to show you how to build a MariaDB docker image with increased connection limits. This is a good method to update configurations at build time when you don't have another option like an environmental variable. Your new MariaDB image can be used in place of the regular MariaDB image and will apply the connection limit. There are a couple of downsides to building your own images, you have to maintain them. This means you will need to periodically update your image by rebuilding. There are also best practices that go along with building Dockerfiles. The main thing with this image is to keep the database up to date (ex. changing the image name from 10.6 to 10.8). We cover this in a bit more detail below but it is important to know before starting that you now have to periodically come back and work on this image.
We do not need a compose example for this project as this is meant to replace the image name on an already existing docker-compose stack. We will only be showing you how to build the image.
We have added a configuration file to increase the connection limit of MariaDB. For high-traffic websites, this may help things run a little smoother, or fix the “too many connections” error message. This number is not arbitrary (in theory) so you really should take this into consideration for what your website needs. If you have too many connections your database may crash. This is a much bigger deal on bare metal than in a container but you still do not want your database to crash EVER (also, you should always have backups of your data somehow to recover from a disaster)!
If you are unfamiliar with creating docker images please visit Dockerfile best practices and continue through the whole “Build images” Section. If you would like to learn how we build images please visit TrueFreedomTech.com and check out our course on Dockerfile. This wiki should still be enough to get you up and running if you have a little bit of experience already, advanced users should be able to take what they learn here and adapt it to their own needs.
We are going to be building these images locally on a windows machine running docker and deploying them on the same machine, the same process applies to Linux.
Step 1: Download files from the True Freedom Tech Dockerfile Repo.
Step 2: Open a terminal and cd
into the folder containing the Dockerfile.
Step 3: Run docker build . -t <your-docker-hub-user>/mariadb:<db-version>
You do not have to use your docker hub user but if you want to push this image to docker hub it is a good idea to do so.
Step 4 (optional): Push to docker hub docker push <your-docker-hub-user>/mariadb:<db-version>
.
*Note: Keep in mind it is a good idea if you change the database version in the dockerfile to tag your image as that database version and only push “latest” if it is the LATEST DB version available. If you run version 10.8 where it should be 10.6 or vice versa you will run into issues!
FROM mariadb:10.8
COPY ./db-limits /etc/mysql/mariadb.conf.d/51-max-connections.cnf
RUN chmod 0544 /etc/mysql/mariadb.conf.d/51-max-connections.cnf
CMD ["mariadbd"]
[mysqld]
max_connections=1000
To use your new database image simply replace the image:
section of your database container in the docker-compose. Make sure your database is the same type of container (Mariadb NOT MySQL) and is up to the same version as the custom DB image.