testcontainers / testcontainers-java

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.org
MIT License
7.97k stars 1.64k forks source link

[Bug]: Incorrect instructions for Rancher Desktop #9096

Closed mwisnicki closed 10 hours ago

mwisnicki commented 1 month ago

Module

Core

Testcontainers version

N/A

Using the latest Testcontainers version?

Yes

Host OS

MacOS

Host Arch

ARM

Docker version

N/A

What happened?

Not related to java but website does not offer instructions how to report documentation bugs

Follow: https://java.testcontainers.org/supported_docker_environment/#rancher-desktop \ Using qemu

~/Projects/oss/slick-pg git:[master]
export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show rd0 | awk '/inet / {sub("/.*",""); print $2}')

ip: can't find device 'rd0'
Error: exit status 1
~/Projects/oss/slick-pg git:[master]
rdctl shell ip a show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:55:55:f4:b6:fb brd ff:ff:ff:ff:ff:ff
    inet 192.168.5.15/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fec0::5055:55ff:fef4:b6fb/64 scope site dynamic flags 100 
       valid_lft 86279sec preferred_lft 14279sec
    inet6 fe80::5055:55ff:fef4:b6fb/64 scope link 
       valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:75:90:1a:0f brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:75ff:fe90:1a0f/64 scope link 
       valid_lft forever preferred_lft forever
4: br-e22ef83c0151: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN 
    link/ether 02:42:a2:3b:2c:bf brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global br-e22ef83c0151
       valid_lft forever preferred_lft forever
54: veth0cb20e6@if53: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue master docker0 state UP 
    link/ether 96:72:38:be:c8:d1 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::9472:38ff:febe:c8d1/64 scope link 
       valid_lft forever preferred_lft forever

Relevant log output

No response

Additional Information

No response

eddumelendez commented 1 month ago

Hi @mwisnicki, thanks for raising the issue. This documentation has been contributed by the Rancher Team and it is the same described in their own docs

@sunilarjun Can you help us, please?

sunilarjun commented 1 month ago

Hello there @mwisnicki and @eddumelendez ! I have re-tested the QEMU steps using Rancher Desktop v1.15.0 and am able to successfully work through the example on macOS M1. Please note that administrative access must be enabled in RD to use QEMU.

@mwisnicki could you please elaborate on your Rancher Desktop version and administrative access enablement? Thank you for any info!

mwisnicki commented 1 month ago

You're right. I didn't have administrator enabled since it causes other issues and Rancher recommends to avoid it. With admin rights I was able get success although there were a lot of exceptions logged related to ryuk

16:31:04.499 [main] INFO  tc.testcontainers/ryuk:0.6.0 - Container testcontainers/ryuk:0.6.0 started in PT0.450284S
16:31:04.504 [testcontainers-ryuk] WARN  org.testcontainers.utility.RyukResourceReaper - Can not connect to Ryuk at localhost:32768
java.net.ConnectException: Connection refused (Connection refused)
        at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
        at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
        at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
        at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.base/java.net.Socket.connect(Socket.java:609)
        at org.testcontainers.utility.RyukResourceReaper.lambda$null$1(RyukResourceReaper.java:105)
        at org.rnorth.ducttape.ratelimits.RateLimiter.doWhenReady(RateLimiter.java:27)
        at org.testcontainers.utility.RyukResourceReaper.lambda$maybeStart$2(RyukResourceReaper.java:101)
        at java.base/java.lang.Thread.run(Thread.java:829)

... repeat many times
16:31:06.811 [testcontainers-ryuk] DEBUG org.testcontainers.utility.ResourceReaper - Sending 'label=org.testcontainers%3Dtrue&label=org.testcontainers.lang%3Djava&label=org.testcontainers.version%3D1.19.4&label=org.testcontainers.sessionId%3D6a39f7da-182e-443b-a8dd-5313bc9c4fb3' to Ryuk
16:31:06.814 [testcontainers-ryuk] DEBUG org.testcontainers.utility.RyukResourceReaper - Received 'ACK' from Ryuk

I guess that normal?

Why can't testcontainer work without Rancher running as admin?

BTW I tried these steps and they seem to work without admin:

export DOCKER_HOST=unix://$HOME/.rd/docker.sock
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock

git clone https://github.com/testcontainers/testcontainers-java-repro
cd testcontainers-java-repro
./mvnw verify

Success

Why can't testcontainer autodetect this? There is already some autodetection code that tries multiple options.

Also don't understand that socker override. Shouldn't it point to $HOME/.rd/docker.sock?

Not sure what's going on here:

docker run -v $HOME/.rd/docker.sock:/var/run/docker.sock -e RYUK_PORT=8080 -p 8080:8080 docker.io/testcontainers/ryuk:0.6.0
2024/08/13 20:45:11 Pinging Docker...
panic: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

goroutine 1 [running]:
main.main()
        /app/main.go:131 +0x410

but

docker run -v /var/run/docker.sock:/var/run/docker.sock -e RYUK_PORT=8080 -p 8080:8080 docker.io/testcontainers/ryuk:0.6.0
2024/08/13 20:45:20 Pinging Docker...
2024/08/13 20:45:20 Docker daemon is available!
2024/08/13 20:45:20 Starting on port 8080...
2024/08/13 20:45:20 Started!
mwisnicki commented 1 month ago

Using VZ and adding

export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show vznat | awk '/inet / {sub("/.*",""); print $2}')

Fixes the exception logged.

sunilarjun commented 1 month ago

@mwisnicki I am a bit unsure of the exception being seen but currently Rancher Desktop has a how-to guide on a non-admin path for using Testcontainers using VZ emulation, and admin paths for using Testcontainers using QEMU and VZ (RD latest docs link here).

eddumelendez commented 10 hours ago

Closing as the existing docs is valid to use Testcontainers with Rancher Desktop.