Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't connect to host.docker.internal #902

Closed
1 of 5 tasks
dbarrosop opened this issue Nov 24, 2023 · 13 comments · Fixed by #904
Closed
1 of 5 tasks

can't connect to host.docker.internal #902

dbarrosop opened this issue Nov 24, 2023 · 13 comments · Fixed by #904
Labels
bug Something isn't working

Comments

@dbarrosop
Copy link

Description

Not sure what changed between 0.6.2 and 0.6.5 but on <=0.6.2 I could add on my docker-compose file:

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

and then run a service on my laptop and connect from the container directly to it via that name. For instance, if I had on my laptop a service running on :8080 from the container I could simply do curl http://host.docker.internal:8080. Now on 0.6.5 I get "connection refused". I noticed that curl http://192.168.5.2:8080 works but I don't think hardcoding IPs is a good solution, specially when sharing the docker-compose file with others.

Version

colima version 0.6.5
git commit: dev

runtime: docker
arch: aarch64
client: v20.10.25
server: v24.0.7
limactl version 0.18.0

qemu-img version 8.1.2
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers

Operating System

  • macOS Intel <= 13 (Ventura)
  • macOS Intel >= 14 (Sonoma)
  • Apple Silicon <= 13 (Ventura)
  • Apple Silicon >= 14 (Sonoma)
  • Linux

Output of colima status

colima status
INFO[0000] colima is running using macOS Virtualization.Framework
INFO[0000] arch: aarch64
INFO[0000] runtime: docker
INFO[0000] mountType: virtiofs
INFO[0000] socket: unix:///Users/dbarroso/.colima/default/docker.sock

Reproduction Steps

  1. On your laptop run nc -l 8080
  2. docker run --rm --add-host=host.docker.internal:host-gateway -it busybox sh -c 'echo asd | nc host.docker.internal 8080 && echo "success" || echo "failed"'
  3. docker run --rm --add-host=host.docker.internal:host-gateway -it busybox sh -c 'echo asd | nc 192.168.5.2 8080 && echo "success" || echo "failed"'

For instance:

On one terminal:

$ nc -l 8080

On another:

$ docker run --rm --add-host=host.docker.internal:host-gateway -it busybox sh -c 'echo asd | nc host.docker.internal 8080 && echo "success" || echo "failed"'
failed

$ docker run --rm --add-host=host.docker.internal:host-gateway -it busybox sh -c 'echo asd | nc 192.168.5.2 8080 && echo "success" || echo "failed"'
success

Expected behaviour

Connecting via host.docker.internal should work as it used to on <=0.6.2

Additional context

No response

@abiosoft
Copy link
Owner

Does it work if you remove the extra_hosts section of your docker compose file?

@dbarrosop
Copy link
Author

Yes, it works without it but removing it breaks compatibility with other docker setups. Those lines are there in the docker-compose file to make sure the same docker-compose works across environments. For reference:

moby/moby#40007
docker/for-linux#264

And as mentioned before this was working fine at least up to 0.6.2 (I upgraded this morning from 0.6.2 to 0.6.5 so unsure which version broke this).

BTW, awesome work with colima, huge fan here :)

@abiosoft
Copy link
Owner

abiosoft commented Nov 24, 2023

Yeah, I am not asking you to remove it, I am only trying to confirm if it's only the host-gateway that's broken or the DNS.

I suspect it is (docker daemon) configuration related.

Thanks for reporting.

@abiosoft abiosoft added the bug Something isn't working label Nov 24, 2023
@rfay
Copy link
Contributor

rfay commented Nov 24, 2023

In DDEV we only add that on Linux docker-ce systems, since host.docker.internal is provided by other systems like Docker Desktop/Colima/OrbStack everywhere. However, it would be nice if it worked both ways (provided by the docker setup and added by --add-host=host.docker.internal:host-gateway

@abiosoft
Copy link
Owner

The issue has been found.

For whatever reason, the docker daemon is not picking up the host-gateway-ip from the daemon config file. However, configuring dockerd via systemd works.

Fixing in #904.

@abiosoft
Copy link
Owner

This should be fixed by now. You can verify by installing the development version brew install --head colima.

Thanks.

@dbarrosop
Copy link
Author

Perfect, I can confirm it works now. Amazing work and thanks!

@rfay FWIW we always add it because it is basically a NOOP in docker-for-mac and other systems that add it automagically and it adds a consistent behavior across development environments.

@skipdegroot-avisi
Copy link

@dbarrosop Does this still work for you in 0.6.7? I'm running into the same issue on my Sonoma 14.2.1 machine by the looks of it:

$ colima version && limactl --version && qemu-img --version
colima version 0.6.7
git commit: ba1be00e9aec47f2c1ffdacfb7e428e465f0b58a

runtime: docker
arch: aarch64
client: v24.0.7
server: v24.0.7
limactl version 0.19.1
qemu-img version 8.2.0

$ docker run --rm --add-host=host.docker.internal:host-gateway -it busybox sh -c 'echo asd | nc host.docker.internal 8080 && echo "success" || echo "failed"'   
failed
$ docker run --rm --add-host=host.docker.internal:host-gateway -it busybox sh -c 'echo asd | nc 192.168.5.2 8080 && echo "success" || echo "failed"'
success

I have tried rebooting, starting over after a colima delete and switching from vz to qemu virtualisation. Nothing seems to fix this except removing the host.docker.internal:host-gateway line which also isn't preferred here due to multiple different development environments within the same team.

@dbarrosop
Copy link
Author

Yeah, this seems broken again in 0.6.7

@markaschneider
Copy link

Yup, not working for me in 0.6.7

@opticoder
Copy link

Not working with 0.7.0 also

@abiosoft
Copy link
Owner

abiosoft commented Aug 9, 2024

Can you try the current development version? brew install -head colima.

@opticoder
Copy link

Can you try the current development version? brew install -head colima.

Just checked - works fine. Hope the fix will land in the next colima version

tmeijn pushed a commit to tmeijn/dotfiles that referenced this issue Aug 10, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [abiosoft/colima](https://github.com/abiosoft/colima) | patch | `v0.7.0` -> `v0.7.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>abiosoft/colima (abiosoft/colima)</summary>

### [`v0.7.1`](https://github.com/abiosoft/colima/releases/tag/v0.7.1)

[Compare Source](abiosoft/colima@v0.7.0...v0.7.1)

#### Highlights

This is an incremental release with bug fixes.

-   Interrupted disk image download will now resume on subsequent `colima start`.
-   Docker container port mapping to specific host IP addresses is now supported.

For more details about v0.70 features, check [v0.70 release notes](https://github.com/abiosoft/colima/releases/tag/v0.7.0).

#### Other Fixes

-   Disk image downloader no longer duplicating downloads. Fixes [#&#8203;1098](abiosoft/colima#1098)
-   Support for binding to host IP address in containers. Fixes [#&#8203;492](abiosoft/colima#492)
-   Ensure proper loading of docker deamon settings on startup. Fixes [#&#8203;902](abiosoft/colima#902)
-   Running multiple Colima profiles with k3s enabled. Fixes [#&#8203;1087](abiosoft/colima#1087)

#### Commits

-   k3s: use random port for cluster API by [@&#8203;abiosoft](https://github.com/abiosoft) in abiosoft/colima#1088
-   k3s: re-use default port for existing instances by [@&#8203;abiosoft](https://github.com/abiosoft) in abiosoft/colima#1090
-   net: support forwarding to specific host IP addresses by [@&#8203;abiosoft](https://github.com/abiosoft) in abiosoft/colima#1091
-   core: nested virtualization and other fixes by [@&#8203;abiosoft](https://github.com/abiosoft) in abiosoft/colima#1094
-   build(deps): bump golang.org/x/term from 0.22.0 to 0.23.0 by [@&#8203;dependabot](https://github.com/dependabot) in abiosoft/colima#1095
-   fix(docker): apply configuration on first boot by [@&#8203;milas](https://github.com/milas) in abiosoft/colima#1097
-   core: fix downloader duplicating downloads by [@&#8203;abiosoft](https://github.com/abiosoft) in abiosoft/colima#1099
-   core: update disk images by [@&#8203;abiosoft](https://github.com/abiosoft) in abiosoft/colima#1102

**Full Changelog**: abiosoft/colima@v0.7.0...v0.7.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants