Docker Community Forums

Share and learn in the Docker community.

Docker MySQL container can't be connected from localhost

Hello everyone. I am using a custom docker-compose file named mysql.yml. I am runnin it by docker-compose up -f mysql.yml -d command and docker container created successfully. Here is the problem, I can’t connect that MySQL database from IDE or any application. I use same configuration in different linux distributions (ex. Ubuntu, Pop_OS!, Manjaro), but for some distributions(ex. Fedora Workstation 33, 34), I can’t connect to it. I need to use docker in my current OpenSUSE Thumbleweed setup, any help appreciated. I am working on this issue longer than 1 week and couldn’t solve it. I can give any necessery info.

Docker version 20.10.6-ce, build 8728dd246c3a
docker-compose version 1.28.5, build unknown

Here is my custom mysql.yml file:

version: '2'
services:
  demo-mysql:
    image: mysql:5.7.18
    restart: always
    environment:
      - MYSQL_USER=freightest_prod_user
      - MYSQL_PASSWORD=ua8W5Un_JmQqnF3Y
      - MYSQL_DATABASE=freightest_prod_db
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
    ports:
      - 3306:3306

Some docker-compose examples use
MYSQL_HOST=db

Not sure about your case though. Your docker-compose looks different from others.