Database comparison is a useful process that helps us understand how data performs in different systems and choose which is the most effective solution to use. However, because relational databases are powered by many different systems, each providing a specific purpose, selecting the right database system can be difficult.
To understand how to simplify database selection, I ran my own tests by installing multiple relational databases on a local machine using Docker Compose, so that I could test and evaluate them.
In this article, I will walk you through how to set up multiple relational databases on your local computer using Docker and share my findings from completing this process. Through setting up databases on your local computer with Docker, you will be able to learn about, compare, and develop them in a pain-free and efficient manner, to ultimately select the best one for your specific needs.
In addition, this piece explains how to use Docker and Docker Compose, and provides relational database Docker Images as a guide to installing four relational databases on your computer: PostgreSQL, MariaDB, Microsoft SQL Server, and Oracle. Once these databases are built, you will be able to learn how they work and compare their features. We will also be able to create a local development environment that will serve as the basis for personal development, and much more!
What is a Database and Why use Docker?
A database is a tool used for storing and accessing collections of data. Databases can store data in many formats, including documents, unstructured objects, networks (or “graphs”) of entities, and structured relational data. Relational databases are some of the most common databases and are powered by many different database systems. Many of these systems are good for specific instances, used with specific purposes and kinds of data, and can have specific features. Choosing the right relational database system is important but can prove difficult. Beyond choosing what features are right for you, setting up a database for evaluation is often hard and requires specific knowledge about how that system should be constructed.
Fortunately, there is a tool that can help us reduce the complexity of setting up multiple databases: Docker. Docker can construct services like relational databases easily, quickly, and consistently. Docker does this with files called images. Images are instructions for computing environments (containers), that run on your local machine. These containers provide customizable, isolated computing environments, that you can specify and control with great precision. They can be specified and controlled with a tool called Docker Compose.
This article discusses setting up four popular relational database systems: PostgreSQL, MariaDB, MS SQL Server Express, and Oracle XE. Each of these systems can be very different:
- Open-source database system.
- PostgreSQL is powerful enough to handle complex queries.
- PostgreSQL comes with many features to protest data integrity and build fault-tolerance environments and low maintenance.
- Open-source database system.
- MariaDB is more commonly used for light data use cases and lower memory environments (but it can be used for heavy data use cases as well!).
- MariaDB is highly compatible with the popular MySQL database engine.
Microsoft SQL Server Express
- Microsoft SQL Server Is a commercial database system developed and licensed by Microsoft.
- Microsoft SQL Server Express is a free version of Microsoft SQL Server
- MS SQL Server Express is the best choice for independent software developers and vendors to build client applications.
Oracle Database XE
- Oracle Database is a commercial database system developed and licensed by Oracle.
- Oracle XE can accelerate queries on large data sets using Oracle In-Memory Column Store and database queries using table partitions. This can easily be scaled to Oracle Database on-promises or Oracle Database Cloud.
- Oracle Database Express Edition (XE) is a free version of Oracle Database.
Relational Database Installation with Docker Compose
To set up these four relational databases on your local machine as Docker images, we need to create Docker code that defines each image. We can define Docker images in a file called a Dockerfile. Dockerfiles allow us to pull images and image definitions from a centralized repository called Docker Hub.
Once we have created these images, we will be able to run them as containers using Docker Compose. Each of these image codes will need some additional configuration code to run as a container, which is available in the attached code examples.
Here is the Dockerfile code to create a PostgreSQL Docker image, downloaded from Docker Hub:
Here is the Dockerfile code to create a MariaDB Docker image, downloaded from Docker Hub:
Microsoft SQL Server&
Here is the Dockerfile code to create a Microsoft SQL Server image, downloaded from Docker Hub:
Oracle doesn’t have an official Oracle Database XE image in Docker Hub. However, you can create an image with these downloadable instructions. After you’ve generated an image, you can reference it in a Dockerfile, like with PostgreSQL, MariaDB, and Microsoft SQL Server:
To run these four images on your local machine as Docker containers, we will create a Docker Compose code that defines how each image should run. Using Docker Compose to run these images as containers allows us to automate and save the process as a file that we can refer to repeatedly and enable us to set up and run each database system simultaneously.
Now we can run this code and set up our databases with a single command! Open your command-line interface (for example, the Terminal application on a MacOS machine), change directories to the directory that has the Docker Compose file in it, and run this command to start running the images as containers:
At this point, you will have four relational database systems running on your computer that are available for use and testing!
You can stop running these images as containers with this command:
Accessing the Database Systems
You can connect to these databases using any database client on your local machine. For example, DBeaver allows us to connect to each database simultaneously:
The address, the database, the user, and the password required to connect to each system are defined in your Dockerfile and Docker Compose file.
You have now set up four relational database systems with Docker and Docker Compose that you can access through a database client! Each of these is a full-fledged database system that you can evaluate for compatibility with your existing data. You can also now test their performance in various use cases to see which works best with your existing applications, and have fun generally exploring them.
If you need data assistance, have questions about the mentioned code, or just want to talk data, feel free to reach out to the U.Group Data Team!
You can learn more about our Data Team’s exciting projects and updates here.