6

My app from container wants to access Mysql from host machine, but is not able to connect. I googled a lot and tried many solutions but could not figure the error, could you please help me on this.

  1. It is a windows image
  2. IIS Website works
  3. Website pages that use DB Connection does not work
  4. Mysql DB is install in local machine (same pc where docker desktop is installed in)
  5. Connection string in app uses 'host.docker.internal' with port 3306.

Tried docker uninstall, reinstall, image prune, container prune, WSL stop and start, host file commenting for below lines:

192.168.1.8 host.docker.internal
192.168.1.8 gateway.docker.internal

Below is the ipconfig from container

enter image description here

Nslookup and Ping commands:

enter image description here

network LS:

enter image description here

Docker Compose:

version: "3.9"
services:
    web:
        container_name: dinesh_server_container
        image: dinesh_server:1
        build: .
        ports:
            - "8000:80"
            - "8001:81"
        volumes:
            - .\rowowcf:c:\rowowcf
            - .\rowowcf_supportfiles:c:\rowowcf_supportfiles
            - .\rowocollectionsite:c:\rowocollectionsite
        environment:
            TZ: Asia/Calcutta

Build image uses: FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8

Host OS: Win 10 Pro 10.0.19043 Build 19043

HyperV is enabled too.

Tried the below too:

extra_hosts:
    - "host.docker.internal:host-gateway"

Since it is on windows OS - host network mode is not supported (per my research)

EDIT: MYSQL Bind Address is 0.0.0.0:enter image description here

surpavan
  • 1,372
  • 7
  • 34
  • 66

1 Answers1

2

Maybe the problem is not directly related to docker but to mysql.

Please, try making your local mysql database listen in all the network interfaces of your host: by default it only listens in 127.0.0.1 and for this reason perhaps docker is unable to connect to it.

I am not sure about how to do it in Windows but typically you need to provide the value 0.0.0.0 for the bind-address configuration option in mysqld.cnf:

bind-address = 0.0.0.0

Please, consider review as well this article or this related serverfault question.

From a totally different point of view, I found this and this other related open issues in the Docker for Windows repository that in a certain way resembles your problem: especially the first one provides some workaround for the problem, like shutting down the wsl backend and restarting the docker daemon. I doesn't look like a solution to me, but perhaps it could be of help.

jccampanero
  • 50,989
  • 3
  • 20
  • 49
  • Tried that too, I am able to connect to mysql from different machine already. Problems is probable docker setting only since ping is not working (IMO). Updated the pic showing the mysql bind address in question body. – surpavan Oct 30 '22 at 19:35
  • Thank you for the feedback @surpavan, and sorry, I didn't really your ping image initially. I updated the answer with further information, in fact, totally different: there seem to be different open issues that resemble your problem. They provide some workarounds, although honestly, as I said in the answer itself, they don't seem solutions to me. Is the error present if using HyperV as the underlying backend? – jccampanero Oct 30 '22 at 23:43
  • Thank you for the time @jccampanero ; I did go through those pages and I did try all of them already. I guess windows compatibility is sometime awkward :) – surpavan Oct 31 '22 at 17:45
  • 1
    You are welcome @surpavan. I am sorry because you were unable to find a solution in the mentioned pages. Yes, I agree with with, the product is wonderful but certainly you will get the most of docker if running linux. If you don't mind, I will keep the answer just in case it could be of help to others. I will try finding further ideas: probably a good way to go will be to integrate mysql in your docker stack, use the mysql container, with docker compose, for example, if possible when using windows, until the problem is solved. I hope you find a solution. – jccampanero Oct 31 '22 at 19:13
  • :) thank you for all the support. I tried mysql image (linux only) and it worked fine. But since my app is windows image - docker desktop needs switching from windows to linux mode; even after switching it does not connect. I tried to install mysql in windows using chocolate installers - but configuring mysql was a bit of a challenge (mainly when creating new containers). – surpavan Nov 01 '22 at 19:55
  • You are welcome mate. Yeah, I understand @surpavan. Yes, because on one hand you have the mysql image, based in linux, and in the other, Microsoft doesn't offer support for linux in their .NET Framework docker images... Sorry, I missed this last point in my previous comment. Searching for additional information I found [this related SO question](https://stackoverflow.com/questions/70759531/create-a-linux-based-docker-file-for-net-framework-project): the drawback is that it uses mono, so probably the resultant image will not have the same performance as the native one that it may be an option. – jccampanero Nov 01 '22 at 23:26
  • sure thank you, will have a read. – surpavan Nov 03 '22 at 16:28