I was wondering rather than bring up multiple instances of mysql. Is it possible to reference to a container running defined in an external docker-compose?
I feel like i’m doing a bit too much with docker-compose and some of this would be better suited for K8 but till i’m ready to move to K8, it would be nice to consolidate on a single DB instance.
Though, there is a drawback: usualy the databases only execute database initialization scripts when the datbase file is empty. As such, you will need to add the required database and users for each application you are going to add yourself.
If you create a network from the cli. You can declare it in the compose.yml files as “external”, then assign your containers to this network. You need to think, rather you want to use a single “database” network, which will result in all applications will be able to communicate using the database network, OR wether you create a distinct network per application - which will make the database to be available in n-networks…
Like it was mentioned there is no bootstrapping of the database once data exists. So you’ll have to create a new user manually. I keep the init scripts in the respective directories even if they’re not being executed automatically.
MySQL
CREATE DATABASE podcast;
CREATE USER 'podcast_user'@'%' IDENTIFIED BY 'Secret';
GRANT ALL PRIVILEGES ON podcast.* TO 'podcast_user'@'%';
PSQL:
CREATE DATABASE podcast;
CREATE USER podcast_user WITH encrypted password 'Secret';
GRANT ALL privileges ON DATABASE podcast TO podcast_user;