Consider a web-app with 5 micro-services deployed with Docker, and a MySQL container dedicated to storing data produced from other services (shared-database pattern). How should I make the connection between the MySQL container and other containers?
Currently, I am converting a monolith application software into micro-service architecture. The problem is that SQL queries (used to insert data in the database) were written within each module of the software (service) such that when a module is called or initiated, a connection to the main MySQL database from that module is also initiated inside the module. The functions used to execute queries and connect to MySQL are imported/called by each module from a custom python library that I have built.
Should I make the services communicate with the MySQL container directly (i.e. write the SQL functions into the MySQL container and make them available as API endpoints) or should I keep the current library and connect each service to the main MySQL database with the SQL functions? The second option may require to define MySQL credential information as environment variables within each service container.