4 Ready-made MySQL Database Docker Images
MySQL is a widely used Relational Database Management System (RDBMS) across organisations large and small. Companies using MySQL for their database needs include Facebook, YouTube, and Booking.com.<!--more-->
In this post, we take a look at four ready-made MySQL related Docker images. For each one, we’ll address some of the current issues that may affect you when using the image, and offer ways to work around them.
MariaDB is an open source, community-based fork of the original MySQL project, led by the original developers of MySQL. MariaDB offers drop-in replacement capabilities, library binary equivalency, and exact matching with MySQL APIs.
MariaDB includes two new storage engines: XtraDB (a replacement for innoDB) and Aria (a replacement for MyISAM). Aria is both a transactional and non-transactional engine, offering even more flexibility to developers working with MariaDB.
If you’re using Boot2Docker to manage your Docker containers, There is a known bug which causes connection issues between containers and hosts. As a result, you’ll need to map these ports at the VM level rather than within Boot2Docker itself.
There are a number of ways to do this, the simplest being to run:
Boot2Docker offers workarounds on GitHub for people with multiple containers exposing the same port. To do this, shut down your VM, then running the following command, which uses Docker’s dynamic port forwarding to allow access to multiple servers without using SSH to then locally forward the requests:
These allows ports to be mapped successfully in MariaDB on Boot2Docker.
LAMP is short for Linux, Apache, MySQL, and PHP. LAMP, then, is a web stack with Linux as the base operating system, Apache as the web server, MySQL for the database, and PHP as the programming language. (Though some people swap Python for PHP.)
LAMP is a very common development stack, and owing to its roots in VPS hosting, it is common to bundle all the components together onto one server. This image does just that, and makes it easy to get your LAMP application up and running.
If you’re working on Windows, be careful when cloning this image via MSysGit. There is a bug which produces EOF (end-of-file) errors, mangling line-endings in critical files. This causes the image to fail to build. The solution provided is to use
sed to replace
\r on a file by file basis. No other solution is available as of yet.
Pantheon MySQL Proxy
Pantheon is a WordPress and Drupal hosting platform, providing automated DevOps and scalability. The Pantheon MySQL Proxy Docker image dynamically proxies MySQL queries made against it to a preconfigured Pantheon site at runtime.
Users are able to configure, deploy, and manage static endpoints with credentials that point back to their site’s Pantheon database without running into problems that could occur from server upgrades or migrations. If a particular query does not forward to the correct database, correcting this is as simple as restarting the container.
Pantheon offers an extensive GitHub repository for users that cannot have Docker manage their iptables due to potential conflicts that would arise as a result. Normally, Docker handles iptables on its own, which can be both beneficial and harmful if one’s project has multiple programs accessing iptables.
You can use this tool with against a running container by running:
This will call Docker Inspect on the running container, returning port mappings along with adding or deleting rules from
/etc/iptables.d. Additionally, this command will call
systemctl restart iptables.service to load or remove rules from the currently running configuration.
The official MySQL Docker image is the choice of many developers when managing their database in a containerized workflow. The MySQL Docker image allows for a quick and easy deployment of MySQL, with the official images having been optimized for performance and stability.
There are three current official MySQL Docker images available: 5.5, 5.6, and 5.7.
MySQL 5.6 is the current GA version, and 5.7 is the current development milestone server. As such, unless you are working on the bleeding-edge of MySQL technology, working with the MySQL 5.7 image could result in application-breaking bugs or errors as the image is updated according to the current roadmap.
Currently, users running Travis CI may experience a bug where MySQL will time out during a container build. When the container build process reaches
debconf: falling back to frontend: Teletype the container will hang, then terminate the build. There is currently no workaround for this issue.
If you are working on a Mac, you may run into issues trying to connect to a MySQL Docker container on
localhost. By default, MySQL attempts to connect using an IPC socket when you specify
localhost, so switch to
Next, you should run:
docker-compose command creates your application environment, sets up services that run your application, and runs the image. Using
--service-ports maps the port correctly and allows you to connect to your database as if it were running locally.
In this post we looked at the Docker images for:
- MariaDB: an open-source fork of MySQL
- LAMP: a popular web stack that includes MySQL
- Pantheon MySQL Proxy: a dynamic proxy for MySQL queries
- MySQL: the official MySQL image
These four projects are just a few examples of ready-made MySQL Docker images available on the Docker hub.