MySQL Docker Containers AsyncThis blog discusses a few concepts about Docker and how we can use it to run a MySQL async replication environment. Docker is a tool designed to make it easier for developers and sysadmins to create/develop, configure, and run applications with containers. The container allows us to package all parts of the application it needs, such as libraries, dependencies like code, configurations, and runtime engine. Docker runtime containers are platform-independent so the package created can be shipped one platform to another platform.

Dockerhub is the repository where you can find containerized docker images for applications like MySQL, Percona Server for MySQL, and MariaDB. Using the example below, I will show you how to set up a docker container from the Pecona Server for MySQL docker image that I download from the repository.

Custom Network Instead of the Default

First, I will create a network that my docker instances will use. I will be using a user-defined network instead of the default one. It is recommended to use the user-defined bridge networks to control which containers can communicate with each other. Docket daemon automatically takes care of DNS name resolution. By creating your own network, every single container using that network will have DNS resolution automagically.

Storage for Persisting the Data

The second step is to provision the storage which my docker instances will be using. In docker, storage can be provisioned in two ways, by using a bind mount or by using a docker volume. Bind mounts are dependent on the directory structure of the host machine while docker volumes are completely managed by Docker. In my example, I am using bind mounts for the primary instance and docker volumes for the replica to illustrate how either of these options can be used.

Configuration File for the Primary Instance

I will proceed with the creation of the configuration file which my primary instance will be using.

Provisioning the Primary Instance

In the fourth step, we will provision the primary instance. The docker run command will download the latest percona server image if the image does not already exist in the local repository. In this example, we already have the downloaded image so the docker run does not need to download it again.

I intend to set up an async replication environment, so I will get the binary log details from the primary instance.

For setting the replication we need a user and the below command connects the primary instance and grants the privilege.

Docker Volume for Replication Storage

Before I create my replica instance, I will provision the docker volume which my replica instance will use for storage.

Configuration File for the Replica Instance

Create a custom MySQL configuration file for the replica instance.

Provisioning the Replica Instance

The next step is to set up a replica instance using the docker volume that I created above.

To set up the replication, apply the change master command in the replica instance and start the replica.

Verify the Replication Status

Create a test DB to confirm it is replicating to the replica instance.

To check the logs we can use the docker logs command, for example :

The setup that I have shown above can be used as a quick setup of an async replication configuration to run demos or test experiments. Such a configuration is not suitable for a typical production install and you need to test it well before any other use.

Note: Percona Monitoring and Management (PMM) is also distributed as an appliance in the form of a docker image.

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Charlie Arehart

Thanks for that, Arunjith. I’m sure many will appreciate the succinct steps.

That said, I think many others would benefit if you could elaborate on the last sentence. First, what makes this configuration “not suitable for production”? Is that a licensing point, or some other legal or technical point?

If you may be implying merely that this one image (without orchestration) might not stand up to load, that could still “work” as production for some implementations, who without docker may also be only one instance. Heck, just adding replication will be a step up for some.

Of course, I appreciate the real value such a docker-based configuration adds for development and testing. I just really seek your clarification on what does make this NOT suitable for production.

Finally, still more curious, you add that it would “not be supported for production use by Docker”? That too is a point I’d think many would benefit hearing elaborated. Thanks.

Arunjith A

Hi Charlie, Thanks for the response. The aforesaid details are the basics to get a test instance running quickly and easily including the async replication and not for a production setup. It is clearly a technical point, it does not match a typical production install and you need to test it well before any other use.

carehart

Ok, so it’s not really that it “it IS not suitable to production”, but rather that it “may not be”. I gather you won’t be changing it, but I offer this for the sake of other readers, barring any additional clarification from you or others. (Your concluding point about testing is understood and doesn’t counter what I’d said).

Finally, you still haven’t explained your last point, that this “will not be supported for production use by Docker”. Can you please elaborate?

I’m sorry if it seems I’m “looking a gift horse in the mouth”, in pressing these points. But they seem reasonable ones, given how the article kind of turned on a dime with that last sentence. It’s just not clear that things are as firm as you said, without more clarification.

Arunjith Aravindan

Changed the text for better clearly, all set! Thanks.

Jojo Thomas

Can you also advice on the steps to get a local mysql install on my MacBook Pro

—-
❯ mysql -h127.0.0.1 -uroot -p -P3308 -e “show master status;”
zsh: command not found: mysql

Jojo Thomas

Got it:
❯ brew install mysql-client
❯ brew link mysql-client
❯ echo ‘export PATH=”/usr/local/opt/mysql-client/bin:$PATH”‘ >> ~/.zshrc
❯ . ~/.zshrc