If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Running MYSQL in Docker Containers for Production

Started by Alicerraq, Jun 26, 2023, 07:10 AM

Previous topic - Next topic

AlicerraqTopic starter

Is it a good idea to use mysql within a docker container for production purposes? The main objective is to shift websites from shared hosting to VPS and have them operate in isolated docker containers. Since I'm not familiar with docker, this is the approach I've devised:
nginx (proxy) -> [container 1(apache + php + mysql)] <= volume(site 1 + database 1)
nginx (proxy) -> [container 2(apache + php + mysql)] <= volume(site 2 + database 2)
However, I was cautioned that utilizing mysql in a production container may not be advisable. Can you elaborate on the potential issues or drawbacks of deploying mysql in a container, even if the database itself is situated on the docker host?
  •  


oqvjAcourseTors

When you make changes to files (databases) in a container, they are not stored and will be lost when the container is restarted. This feature can be helpful for testing, but not for actual work as it resets the entire database to its initial state.

To save changes to your data, there are specific steps you need to take. Consistency between the database and container requires constant monitoring and updating of the container after any changes to the database. However, this process can create significant strain.
  •  

patricka

Some advice to optimize your Docker setup:
1. Consider switching from Apache to nginx in 2018 as it offers more benefits. If you have routing rules tied to Apache, try translating them to nginx.

2.

It's best to have one container per process (PHP and nginx separately) instead of running everything in one container. This will make it easier to use standard images for each process. If you're still using Apache, you may have one container with Apache and PHP since you're probably using the doctor module, but it's better to avoid Apache altogether if possible.

3.

In production, it's best to build your own image based on a standard one that has your code added at the build stage instead of using volumes for the code. This way, you can deploy the container as a whole instead of having to put your code in a folder. The system will be more stable and portable as a result.

4.

You don't need to run MySQL in a container due to the overhead of having a separate instance for each site and the need to provide data persistence. Instead, run MySQL on a separate server or even the same one as Docker to save resources and avoid complications with slow volumes. Once you've sorted out MySQL, take a look at dockerizing the database again.
  •  

Teeproria

Expect substantial disk space usage with this tool, so be prepared. However, there shouldn't be any other issues. While using a database in a container may cause some overhead, this is offset by the lack of database server settings (have you optimized the server for your current load profile?) and the structure of the database itself (has anyone tested query performance with the scheduler?). Therefore, there's no need to worry about these factors.

It's generally recommended not to store data within containers. Instead, use the volume mechanism to store the database file outside of the container.
  •  

Spatanie

One of the primary concerns when running MySQL within a Docker container is performance. Database systems like MySQL often require careful resource management, including memory allocation, disk I/O optimization, and CPU utilization. Running MySQL within a Docker container adds an additional layer of abstraction, potentially impacting performance due to the overhead of containerization. Tuning the containerized MySQL instance to effectively utilize system resources becomes critical, as unsuitable resource allocation can lead to performance bottlenecks and reduced responsiveness for website applications.

Security is another significant consideration. Docker containers, if not properly configured and secured, can introduce vulnerabilities that may expose the MySQL database to potential attacks. Securing a database system within a containerized environment requires meticulous attention to container security best practices, ensuring that access controls, network configurations, and container isolation mechanisms are robustly implemented to protect sensitive data.

Data persistence and management pose additional challenges when deploying MySQL within Docker containers. While you mentioned situating the database itself on the Docker host, ensuring persistent storage for database files and managing backups becomes more complex within the context of containerized environments. The need to maintain data integrity and availability while accommodating container lifecycle events such as scaling, updates, and restarts requires careful consideration and implementation of suitable persistence solutions.

Deploying multiple instances of MySQL within separate containers for different websites introduces operational complexities. Effective resource allocation, load balancing, monitoring, and maintenance of the database instances become more intricate and potentially more error-prone, especially when considering the varied resource demands and data access patterns of different websites.
An alternative architectural approach involves decoupling the database layer from the containerized web server and application components. This entails leveraging dedicated database servers outside of Docker containers, allowing for more granular control over performance tuning, security hardening, and data management. By separating the database layer, you can streamline resource allocation, scaling, and monitoring, while simplifying the management of database backups and maintenance tasks.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...