0

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.

1 Answer 1

1

You seem to have a minor misconception about accessing databases. No application other than the database itself should be modifying raw database files, and all other applications should interface with the database in order to access or modify information.

2: A large majority of databases as docker images follow a convention, that is passing configuration variables through environment variables. Refer here: https://mariadb.com/kb/en/installing-and-using-mariadb-via-docker/

When you attempt to bind mount /a/path:/config, you are trying to bind mount /a/path on your local system to /config in the docker container. To my knowledge, this directory most certainly does not exist in the MariaDB docker.

3: Where are the database data files kept? According to MariaDB, the default location is /var/lib/mysql.

5: You can pass them as environment variables as mentioned in #2. I do not understand what you mean by a "good idea", but it is certainly doable, and is standard.

7: As mentioned before, you should not.

8
  • hmmm, Then files access isn't the issue. As I understand, the docker will ask maria to process the database inquiry and/or ask to get data, right ? But here's the thing, the database name and the host name are both maria_db ... is that a problem? Plus, I gave the mariadb ports like this 5000:3306 ... is reaching it from another docker is with 3306 or 5000 ? thnaks Nov 9, 2023 at 9:35
  • And is it a good idea to give each docker a db_username and password to interface with the database ? Or should they all interface with the database using the same username and password? What is better? Does the database have a way to differentiate between queries ? Thanks Nov 9, 2023 at 9:43
  • 1
    For your first question, you should not need to expose the mariadb port if you are running both containers on the same network. If you want to access it externally, you would access it via <your ip>:5000. Docker plays absolutely zero part in the transaction between Maria and your application. As for your question about the database name, no, this should not pose a problem.
    – sawntoe
    Nov 9, 2023 at 10:01
  • I believe the term you are looking for is application inside a docker container. I am currently unaware of your application structure. As for your question about seperate users, yes, having multiple users is standard for permissions control. As for your question about "does the database have a way to differentiate between queries", I think you need to read up on database transactions and how they work as I cannot everything in such a comment. May I ask why this matters though?
    – sawntoe
    Nov 9, 2023 at 10:05
  • 1
    At this point, I would highly suggest reading up more on production databases and containerization before you take on such an ambitious project, as it seems that you do not understand exactly how production databases work and seem to misuse docker terminology. (Please don't take offense, i do not wish to put you down and this is my advice.) If you need help, feel free to hmu!
    – sawntoe
    Nov 9, 2023 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .