question

CloudRock avatar image
0 Votes"
CloudRock asked CloudRock commented

How to link local docker app with azure database for mysql ?

Hello,

I'm running docker app matomo with docker compose. As of today, the app is using local mysql server to host its databases.

Now, I want to link my local app with Azure database for mysql, I want to know how to substitute necessary variables to keep the app working with the new architecture.

The database variables are defined in 2 files :

  - **FILE 1 : docker-compose.yml :**
    
     version: "3"
     services:
       db:
         image: mariadb
         command: --max-allowed-packet=64MB
         restart: always
         volumes:
           - ./db:/var/lib/mysql
         environment:
           - MYSQL_ROOT_PASSWORD=XXXX
         env_file:
           - ./db.env
         ports:
           - 3306:3306
       app:
         image: matomo
         restart: always
         volumes:
     #     - ./config:/var/www/html/config
     #     - ./logs:/var/www/html/logs
           - ./matomo:/var/www/html
         environment:
           - MATOMO_DATABASE_HOST=db
         env_file:
           - ./db.env
         ports:
           - 8080:80
     volumes:
       db:
       matomo:
    
  - **FILE 2 : db.env :**
    
     MYSQL_PASSWORD=XXXX
     MYSQL_DATABASE=matomo
     MYSQL_USER=matomo
     MATOMO_DATABASE_ADAPTER=mysql



My guess maybe change db volume and MATOMO_DATABASE_HOST=db to declare remote azure instance ?

Rgds,


azure-database-mysql
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@CloudRock We are checking with our team regarding this and will get back to you.

1 Vote 1 ·

1 Answer

NavtejSaini-MSFT avatar image
1 Vote"
NavtejSaini-MSFT answered CloudRock commented

@CloudRock

We have got response from our team and they have conveyed more info regarding this. If that doesn't resolve the issue, please raise a support issue.

1) From the docker compose file we gather below:
a. Matomo is using a docker container to run MySQL database, instead of connecting to a MySQL DB installation on prem or to a MySQL DB on cloud.
b. Hence the docker compose file (File 1) has a “db” container whipped up too (from a mariadb docker image) – as below. Here, the “volume” is just where the containerized MySQL DB’s data persists.

 5.           db:
 6.             image: mariadb
 7.             command: --max-allowed-packet=64MB
 8.             restart: always
 9.             volumes:
 10.               - ./db:/var/lib/mysql
 11.             environment:
 12.               - MYSQL_ROOT_PASSWORD=XXXX
 13.             env_file:
 14.               - ./db.env
 15.             ports:
 16.               - 3306:3306

c. The app then connects to this db : as specified in “environment” – as below.

 24.             environment:
 25.               - MATOMO_DATABASE_HOST=db
 26.             env_file:
 27.               - ./db.env
 28.             ports:
 29.               - 8080:80

2) Now, if Cx wants to connect to Azure DB for MySQL instead of this local MySQL DB Container instance,
a. We do not need a MySQL DB container at all, hence won’t need to whip the container from a docker image, and in turn won’t need a docker compose at all (docker compose is for multi-container scenario.)
b. Instead, what you can do is pass “MATOMO_DATABASE_HOST=mysqldemosvr.mysql.database.azure.com” env variable while running the docker using docker run itself.
Of course, instead of directly specifying the credentials this way, you can store all credentials like MATOMO_DATABASE_HOST, MATOMO_DATABASE_PORT, MATOMO_DATABASE_USERNAME, MATOMO_DATABASE_PASSWORD, in an .env file and “docker run” by passing this file.
c. Cx can refer to : How to run Matomo in a Docker container while passing database credentials as environment variables - DEV Community. And plug in their Azure DB for MySQL credentials.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your answer.

0 Votes 0 ·

Furthermore, it's possible to declare env variables directly in app settings.

0 Votes 0 ·