abiosoft / colima

Container runtimes on macOS (and Linux) with minimal setup
MIT License
18.9k stars 382 forks source link

Can't connect to host.docker.internal on first start when defined in extra_hosts #949

Closed skipdegroot-avisi closed 1 month ago

skipdegroot-avisi commented 9 months ago

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

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 commented 9 months ago

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 commented 9 months ago

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

giovannidegani commented 7 months ago

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

joshuarli commented 2 months ago

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 commented 1 month ago

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 https://github.com/lima-vm/lima/issues/2556