0

I have created a MySQL image on my Windows 10 using the default settings from Docker.

I started the container using this command:

    docker run --name local-mysql --network="host" -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d <your-docker-Image>

I used the --network parameter in the hope that I could connect to the container from my host computer.

Then I ran this command to connect to the container from the MySQL shell

    docker exec -it mysql bash -l

I was able to connect using this

    mysql -h localhost -P 3306 --protocol=tcp -u root -p

Using Delphi and setting FireDac to use DriverId MySQL, I specified host as localhost, port 3306, user as root and the password.

But I get this connection error

    [FireDAC][Phys][MySQL] Cannot connect to MySQL server on 'localhost:3306' (10061)

I have tried using 127.0.0.1 and 0.0.0.0 without success and with the same error.

I would appreciate it if anyone has tried it with Delphi FireDac to connect to a MySQL container hosted on the same computer.

Thank you in advance.

JennyL
  • 81
  • 5

1 Answers1

0

I was able to solve the issue by using this command to run the image

    docker run --name local-mysql -p 127.0.0.1:3307:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d <your-docker-Image>

I used a different host port (3307) to map to the default 3306

I was able to test it using the bash first

    mysql -h 127.0.0.1 -P 3306 -u root -p

And in Delphi FireDac, I used the following to connect

    Host=127.0.0.1
    Port=3307
    User_Name=root
    Password=my-secret-pw

And all is good. Hope this helps someone who is trying to the same.

JennyL
  • 81
  • 5
  • Could it be that you were already running a mysql on your host machine that blocked 3306 from being reused to map to the container ? You should be able to run it on any port, no ? ( PS I'm trying the reverse, connect from delphi docker app to a mysql running on the host :-) and afterwards running in another docker container... – DDeberla Jan 17 '22 at 16:49