Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to run MySQL in Docker

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to run MySQL in Docker. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Data security issues

Do not store data in containers, which is one of the official Docker container tips. The container can be stopped or deleted at any time. When the container is dropped by rm, the data in the container will be lost. To avoid data loss, users can use data volume mount to store data. However, the Volumes design of the container is to provide persistent storage around the Union FS mirror layer, so there is a lack of guarantee for data security. If the container suddenly crashes and the database is not closed properly, the data may be corrupted. In addition, the sharing of data volume groups in the container also does great damage to the physical machine hardware.

Performance problem

As we all know, MySQL is a relational database and has high requirements for IO. When a physical machine runs more than one, IO accumulates, which leads to IO bottleneck and greatly reduces the read and write performance of MySQL.

In a special session of ten difficulties in a Docker application, an architect of a state-owned bank also pointed out: "the performance bottleneck of the database generally appears on the IO. If you follow Docker's way of thinking, then multiple docker requests will eventually appear on the storage. At present, most of the Internet databases are share nothing architecture, which may be a factor that does not consider the migration to Docker."

In fact, there are some corresponding strategies to solve this problem, such as:

(1) Separation of database programs and data

If you use Docker to run MySQL, the database program needs to be separated from the data, the data is stored in shared storage, and the program is placed in a container. If the container has an exception or MySQL service exception, automatically start a brand new container. In addition, it is recommended not to store the data in the host. The host and the container share the volume group, which has a great impact on the damage of the host.

(2) run lightweight or distributed databases

When lightweight or distributed databases are deployed in Docker, Docker itself recommends that the service hang up and start the new container automatically, instead of continuing to restart the container service.

(3) rational layout and application.

For applications or services with high IO requirements, it is more appropriate to deploy the database in the physical machine or KVM. Currently, both Tencent Cloud's TDSQL and Ali's Oceanbase are directly deployed on physical machines rather than Docker.

State problem

Horizontal scaling in Docker can only be used for stateless computing services, not databases.

One of the important features of Docker rapid expansion is stateless, and those with data state are not suitable to be placed directly in Docker. If databases are installed in Docker, storage services need to be provided separately.

Currently, both Tencent Cloud's TDSQL (Financial distributed Database) and Aliyun's Oceanbase (distributed database system) run directly on physical machines, not on Docker that is easy to manage.

Resource isolation

In terms of resource isolation, Docker is really not as good as virtual machine KVM,Docker, which uses Cgroup to achieve resource restrictions, which can only limit the * * value of resource consumption, but cannot isolate other programs from occupying their own resources. If other applications take up too much physical machine resources, it will affect the read and write efficiency of MySQL in the container.

The more isolation levels you need, the more resource overhead you will get. Compared with dedicated environments, easy horizontal scaling is a major advantage of Docker. However, in Docker, horizontal scaling can only be used for stateless computing services, and databases are not applicable.

Can't MySQL run in the container?

It is not entirely impossible for MySQL to be containable.

Services that are not sensitive to data loss (such as users searching for goods) can be digitized, using database fragmentation to increase the number of instances, thereby increasing throughput.

Docker is suitable for running lightweight or distributed databases. When the docker service dies, the new container will be started automatically instead of continuing to restart the container service.

Using middleware and containerization system, database can automatically scale, disaster recovery, switch, and have multiple nodes, and can also be containerized.

On how to run MySQL in Docker to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report