Docker MYSQL ERROR

I’m working on a project where my app is intergrating with a database for object detection. When using docker for containerization, I get errors on the database initializations: errors like this

“"2025-10-31 17:54:04 Error: 2003: Can’t connect to MySQL server on ‘None:3306’ (Errno 111: Connection refused)
2025-10-31 17:54:04 Error: 2003: Can’t connect to MySQL server on ‘None:3306’ (Errno 111: Connection refused).”” or this ““025-10-27 12:42:04 2025-10-27 09:42:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.43-1.el9 started. 2025-10-27 12:42:04 2025-10-27 09:42:04+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’ 2025-10-27 12:42:04 2025-10-27 09:42:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.43-1.el9 started. 2025-10-27 12:42:05 2025-10-27 09:42:05+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified 2025-10-27 12:42:05 You need to specify one of the following as an environment variable: 2025-10-27 12:42:05 - MYSQL_ROOT_PASSWORD 2025-10-27 12:42:05 - MYSQL_ALLOW_EMPTY_PASSWORD 2025-10-27 12:42:05 - MYSQL_RANDOM_ROOT_PASSWORD””.. I’m using XAMPP for the database

This is my YAML script

version: ‘3.8’

services:

main_app:

build:

  context: .

  dockerfile: dockerfile.dev

ports:

  - "5000:5000"

volumes:

  - .:/main_app

environment:

  PYTHONDONTWRITEBYTECODE: 1

  PYTHONUNBUFFERED: 1

  FLASK_APP: main.py

  FLASK_ENV: development

  DB_HOST: host.docker.internal

  DB_USER: ${DB_USER}

  DB_PASSWORD: 

  DB_NAME: ${DB_NAME}

  SECRET_KEY: ${SECRET_KEY}

depends_on:

  - db

command: flask run --host=0.0.0.0 --port=5000

db:

image: mysql:8.0

restart: always

environment:

  MYSQL_ALLOW_EMPTY_PASSWORD: yes

  \# MYSQL_RANDOM_ROOT_PASSWORD: "yes"

  MYSQL_ROOT_PASSWORD: 

  MYSQL_DATABASE: ${DB_NAME}

ports:

  - "3307:3306"

volumes:

  - db_data:/var/lib/mysql

volumes:

db_data:

my environment looks like this

DB_HOST=host.docker.internal

DB_USER=root

DB_PASSWORD=

DB_NAME=preds_db

Kindly assist in resolving this error.

1 Like