Docker container use host application

How to have docker without docker desktop so that I have 2 containers service [django and nginx] which share a network and also in the host [wsl2 Ubuntu] mysql is installed.

How to connect django and mysql, django and nginx?

I have able to connect mysql from windows.

This is rather a wsl2 question than a docker questions.

Inside the wsl2 distribution, you can use the ip of the default gateway to connect services on the host:

cat /etc/resolv.conf | grep nameserver | awk '{print $2}'

You might want to create a script in /etc/profile.d, to assign the current ip to a environment variable whenever the WSL distro starts. :

cat <<'EOF' | sudo tee /etc/profile.d/gateway-ip.sh
export DOCKER_HOST=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
EOF

Also, I moved your topic to the General category, as the Community category is use when you want to announce a community event or ask about a community event - Your post is none of those.

I tried your solution and it creates env variable with ip address of wsl host as value

But using that ip address or env variable, the containers still unable to connect to host service [mysql]

But the services is avaliable at host.docker.internal when docker desktop is installed, but i needed that solution without docker desktop installed.

Back in the day before WSLg was available, I used the mentioned approach to render x-applications from WSL2 on a x-server running on the windows host. As in: I accessed a service on the host from the wsl2 distro like this. If it’s not working for you, then it is high likely either a firewall or routing problem.

There is a reason why Docker Desktop exists. It is not “just” a WSL2 distro. It provides plenty of convenient functionality like adding a dns entry (!) to resolve host.docker.internalto the host.

Anyway, the origin of the problem is not related to docker. You just happen to experience it with docker container, but you would also experience it, if you run a native process on wsl2 without docker.

From my perspective this topic belongs into a WSL forum, not in a Docker forum.

works with 172.17.0.1

Make sure docker desktop is fully uninstalled
Also unistall docker in wsl [Ubuntu]
Restart the pc, shutdown wont work
Install docker and use 172.17.0.1 instead of host.docker.internal
Thank you

So mysql is not running on Windows, but instead it running inside the WSL distribution that runs docker-ce?

Since you are able to access mysqd using the ip of the docker0 interface, mysqld must be running inside the wsl distro and listen on 0.0.0.0:3306, and not on the host. In this case of course, it is not a WSL related topic, and clearly is a docker related topic.

Glad you found a solution.