Docker container cannot connect to host wsl. I don't know why.
Check your connection from container to host using this code. This will run curl code from container. alternatively you can do 2 test, using --add-host
or not.
docker run -it --rm --add-host=host.docker.internal:host-gateway alpine sh -c "apk add curl; curl -X HEAD -vvv http://host.docker.internal:3000"
source : microsoft/WSL#6364 (comment)
The solution is get IP wsl and set it directly to container. first get ip using this code. Source solution microsoft/WSL#1032 (comment)
export WINDOWS_HOST=$(ip --json route show default | jq -re '.[].gateway')
export WSL_HOST=$(ip --json --family inet addr show eth0 | jq -re '.[].addr_info[].local')
save it at ~/.profile or ~/.zshrc, rc file
https://dev.to/natterstefan/docker-tip-how-to-get-host-s-ip-address-inside-a-docker-container-5anh
after save environtment variable to system. Set environtment on docker compose file
serives:
services-1:
environtment:
- ACTION_BASE_URL: ${WSL_HOST:-host.docker.internal}