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 on first start when defined in extra_hosts #949

Closed
1 of 5 tasks
skipdegroot-avisi opened this issue Jan 4, 2024 · 5 comments
Closed
1 of 5 tasks

Comments

@skipdegroot-avisi
Copy link

skipdegroot-avisi commented Jan 4, 2024

Description

Issue seems to be the same as in #902 which was fixed in 0.6.6 but seems to be broken again in 0.6.7.

Adding

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

will not allow a Colima docker container connect to the host mac machine and will show a connection refused. With that extra line host.docker.internal will resolve to 172.17.0.1 in the container instead of the expected 192.168.5.2.

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
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

INFO[0005] colima is running using QEMU                 
INFO[0005] arch: aarch64                                
INFO[0005] runtime: docker                              
INFO[0005] mountType: sshfs                             
INFO[0005] socket: unix:///Users/skigroot/.colima/default/docker.sock 

Reproduction Steps

Same as the previous bug with thanks to @dbarrosop for the simple steps:

  1. You need a clean colima instance, so delete and restart your colima instance
  2. On your laptop run nc -l 8080
  3. 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"'
  4. 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:
Warning, this obviously deletes all information stored in your colima VM

$ colima delete
$ colima start
$ 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 on first start as it used to on <=0.6.2 and 0.6.6

Additional context

Status/version outputs are from qemu, but I have ran it with vz virtualisation as well with no change. colima delete and recreating from template with a freshly downloaded ubuntu image also had no effect.

@skipdegroot-avisi
Copy link
Author

Oh I just figured out the simplest workaround:

colima stop
colima start

Apparently this is only broken on the first start of the VM after recreation?

@dbarrosop
Copy link

I can confirm the same behavior. On a newly created instance it fails, after stop/start it works fine.

@skipdegroot-avisi skipdegroot-avisi changed the title Regression: Can't connect to host.docker.internal when defined in extra_hosts Can't connect to host.docker.internal on first start when defined in extra_hosts Jan 8, 2024
@giovannidegani
Copy link

can also confirm the behaviour, it was preventing my laravel + sails + xdebug to work , stop/starting colima fixed it

@joshuarli
Copy link

joshuarli commented Jul 24, 2024

I can reproduce this with colima 0.6.6 on macos 14.4.1 aarch64. delete, start, failed, stop, start, success.

Might try and figure out a faster way to reproduce so I can bisect, any tips? Recreating after a colima delete takes a while, need like a colima delete --keep-cache or something.

colima version v0.6.6
git commit: 9ed7f4337861931b4d0192ca5409683a4b7d1cdc

runtime: docker
arch: aarch64
client: v26.1.3
server: v25.0.4

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/josh/.colima/default/docker.sock

ProductName:            macOS
ProductVersion:         14.4.1
BuildVersion:           23E224

@skipdegroot-avisi
Copy link
Author

Looks like this is fixed in v0.7.1 if I read the latest comments in #902 correctly. A collegae of mine has confirmed that it works on first boot now so I'll close this ticket.

I would wait a day before updating though to ensure that Lima 0.23.3 has propagated trough brew so you don't need to worry about lima-vm/lima#2556

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants