testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

bugfix: rootless container provider not available on macOS

Open kirked opened this issue 1 year ago • 1 comments

Allows rootless container provider on macOS.

kirked avatar Oct 17 '24 21:10 kirked

Hi, thanks for your contribution. Can you elaborate more on this change, please? Testcontainers provides a strategy to look at Docker Desktop rootless. See https://github.com/testcontainers/testcontainers-java/blob/main/core/src/main/java/org/testcontainers/dockerclient/DockerDesktopClientProviderStrategy.java#L14-L25

eddumelendez avatar Oct 17 '24 22:10 eddumelendez

Hi, thanks for your contribution. Can you elaborate more on this change, please? Testcontainers provides a strategy to look at Docker Desktop rootless. See https://github.com/testcontainers/testcontainers-java/blob/main/core/src/main/java/org/testcontainers/dockerclient/DockerDesktopClientProviderStrategy.java#L14-L25

This change enables macOS users to use the RootlessDockerClientProviderStrategy just as Linux users can, by using a Unix socket.

kirked avatar Oct 21 '24 19:10 kirked

This change enables macOS users to use the RootlessDockerClientProviderStrategy just as Linux users can, by using a Unix socket.

This is what I understand by looking at the changes. However, would be helpful is you can link to some documentation in order to make sure this is really the change to do or if requires something else.

eddumelendez avatar Oct 21 '24 19:10 eddumelendez

I was able to make this change from a Clojure REPL via reflection, and that enabled the RootlessDockerClientProviderStrategy to work with no other changes.

Honestly I don't know why macOS was overlooked for this strategy when the UnixSocketClientProviderStrategy has macOS enabled: https://github.com/testcontainers/testcontainers-java/blob/main/core/src/main/java/org/testcontainers/dockerclient/UnixSocketClientProviderStrategy.java#L47

kirked avatar Oct 21 '24 19:10 kirked

That doesn't answer the question. I have installed Docker Desktop and when I look at ~/.docker/run/ is empty. I don't think there is a path for /run/user/ neither. Have you made a special installation of Docker Desktop or another container runtime that uses that location? I'm trying to get more context.

eddumelendez avatar Oct 21 '24 20:10 eddumelendez

No, it's a standard docker install, but not docker desktop, as that is a commercial product and can't be used. I use Colima for the docker machine.

brew install docker docker-credential-helper colima
colima start
colima stop

then edit ~/.docker/config.json to set the context to "colima" and the credsStore to "osxkeychain". If you wanna use macOS virtualization+virtiofs instead of qemu+sshfs edit ~/.colima/colima.yaml and rm -rf ~/.colima/_lima/colima.

From then on, you can just do colima start and use docker as normal (from the cli).

kirked avatar Oct 22 '24 00:10 kirked

Thanks for sharing, don't you need to follow these steps? I tried without removing rm -rf ~/.colima/_lima/colima but TBH, looks like the simple change will not cause effect to make it work with colima automatically. Currently, I would just follow the instructions for a colima integration. LMK if I missing something

eddumelendez avatar Oct 22 '24 00:10 eddumelendez

The question becomes, why the disparity between UnixSocketClientProvider and RootlessDockerClientProvider?

kirked avatar Oct 24 '24 17:10 kirked

Every strategy look for specific paths or configurations that can be achieved only in specific OS and those are not mixed. Follow #9140, this will solve your issue by reading the docker context once is merged.

eddumelendez avatar Oct 31 '24 01:10 eddumelendez