Trying to connect my arduino to MySql Database running in Docker

Hi,

Disclaimer: Only Answer if you have knowledge about docker

I have MRKWIFi 1010 board. I am using RFID, MLX temp sensor and OLED Screen for my project.
I need to have access to MYSQL database which will be running in DOCKER, to store and retrieve data.

Arduino code attached
Here is the docker-compose file

version: "3"

services:
  webserver:
    build: 
      context: ./bin/${PHPVERSION}
    container_name: '${COMPOSE_PROJECT_NAME}-${PHPVERSION}'
    restart: 'always'
    ports:
      - "${HOST_MACHINE_UNSECURE_HOST_PORT}:80"
      - "${HOST_MACHINE_SECURE_HOST_PORT}:443"
    links: 
      - database
    volumes: 
      - ${DOCUMENT_ROOT-./www}:/var/www/html
      - ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
      - ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
      - ${LOG_DIR-./logs/apache2}:/var/log/apache2
    environment:
      PMA_PORT: ${HOST_MACHINE_PMA_PORT}
  database:
    build:
      context: "./bin/${DATABASE}"
    container_name: '${COMPOSE_PROJECT_NAME}-database'
    restart: 'always'
    ports:
      - "127.0.0.1:${HOST_MACHINE_MYSQL_PORT}:3306"
    volumes: 
      - ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
      - ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
     
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: '${COMPOSE_PROJECT_NAME}-phpmyadmin'
    links:
      - database
    environment:
      PMA_HOST: database
      PMA_PORT: 3306
  
     
    ports:
      - '${HOST_MACHINE_PMA_PORT}:80'
    volumes: 
      - /sessions
      - ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/conf.d/php-phpmyadmin.ini
  redis:
    container_name: '${COMPOSE_PROJECT_NAME}-redis'
    image: redis:latest
    ports:
      - "127.0.0.1:${HOST_MACHINE_REDIS_PORT}:6379"

I have tried putting all type of ips (webserver, sql databse, vm machine, host machine) in **char server**but nothing seems to work. i Cant connect to my server and database.
Please help !

Arduino COde.txt (8 KB)

See Arduino - MySQL tutorial

I’ve used Docker occasionally. I expect a few of the regular posters here have too, but I don’t recall it ever being mentioned here, so I wouldn’t expect that you’ll get your answer on this forum.

Also, the Arduino bit is fairly irrelevant - you can test your docker instance more easily with a regular PC. Don’t forget that MySQL config defaults to access from localhost only - if you want a remote device to access it directly you will need to fix the bind-address in config.

And don't be an idiot and use the root user to access the DB from Arduino directly or from a PHP webpage :wink:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.