Sample Header Ad - 728x90

accessing docker database from other docker container(s)

0 votes
1 answer
403 views
This is a very confusing matter to me. I have multiple containers, each comes with it's own database, which creates resources overhead. I've deployed a mariadb container and I want the other containers to use it, but it appears something is always going wrong and I can't figure it out. So here are some notes: 1) When deploying the mariadb I configured it to be on the same docker network as the other services. 2) when deploying mariadb I used bind volume /a/path:/config ... but I can't find folder called config on that path, I can only find a log/ , databases/ and custom.cnf ... should I create the /config directory myself or is it the same as databases? 3) inside the /databases there are /maria_db and /mysql ... where are the databases kept? **NOTE** that I called the database environment variable as maria_db .. so is the databases saved here? 4) The directory /databases/mysql/ and /databases/maria_db/ both have files that seems to me as databases (example .frm , .ibd) but the /mysql has more file extensions that I can't find in /maria_db, (example .MAD , .MAI) and that is confusing ( see next note). 5) If I have to let the other containers use this DB, should I just make environment variables that calls the database (example: MYSQL_DATABASE=maria_db) or should I also give the other dockers access to the databases directory? and if so, **which one?**, /mariadb ,, /mysql ,, or the parent folder /databases that has both? 6) For each docker I want to give a different database username and pass (MYSQL_USER , MYSQL_PASSWORD) is this a good idea?? ( what I know I should add them to the database by console not passing them with variables, except for the first username and password) 7) If I should mount the database directory to each docker that will use it, **where** should I mount it on the docker that will use it? It's a lot of questions I know, but it's a confusing topic that I couldn't figure out myself, even that I spent hours and hours reading (yesterday alone I spent 12 hours on this). Thanks in advance.
Asked by Abd Alhaleem Bakkor (347 rep)
Nov 9, 2023, 07:58 AM
Last activity: Nov 9, 2023, 08:51 AM