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

Is this for WSL1 and/or WSL2: Windows Support -> Windows Subsystem for Linux (WSL) -> Optional - Only if volumes are required:

Open cer opened this issue 3 years ago • 10 comments

This page https://www.testcontainers.org/supported_docker_environment/windows/ describes how to configure WSL to support volume mapping.

Inside the WSL shell, modify the /ect/wsl.conf file to mount the Windows drives on / instead of on /mnt/. (Reboot required after this step).

However, it's not clear whether this applies to WSL1 or/and WSL2.

It would be helpful if this was clarified. There's also a typo.

cer avatar Apr 11 '22 02:04 cer

Hey @cer, thanks for the pointer. This section only applied to WSL1. WSL2 should work, as documented under WSL2 backend. Would you like to provide a PR to correct this?

kiview avatar Apr 11 '22 06:04 kiview

One comment/question.

I have Docker for Windows running on WSL2. I have a test that uses DockerComposeContainer. The docker-compose.yml file has a volume mount ./foo:/etc/foo. The source code is in c:\mydir.

Volume mounting works fine when running (via Gradle) testcontainers from a WSL2 shell. The current directory is /mnt/c/mydir. Testcontainers creates a container with /mnt/c/mydir/foo mounted correctly

But when I try the same thing in Power shell the volume mounting doesn't work. The current directory is c:\mydir. Testcontainers creates a container that tries to mount /c/mydir/foo instead of /mnt/c/mydir/foo

cer avatar Apr 18 '22 01:04 cer

Does it work correctly if you use docker-compose directly?

kiview avatar Apr 18 '22 13:04 kiview

Does it work correctly if you use docker-compose directly?

Yes.

cer avatar Apr 18 '22 13:04 cer

Does it work correctly if you configure DockerComposeContainer using withLocal(true)?

kiview avatar Apr 18 '22 13:04 kiview

Unsure. my Windows machine is running Docker Compose 2 so I've been using withLocal(false)

cer avatar Apr 18 '22 13:04 cer

It would help to triage if you can try to use it with withLocal(true), you can switch to Docker Compose 1 in the Docker Desktop settings.

But likely, this exact combination (Testcontainers with DockerComposeContainer file mounting and containerized Docker Compose on Docker Desktop with WSL2 backend from Windows process) does not work.

kiview avatar Apr 18 '22 14:04 kiview

Sorry for the delay. It works with withLocalCompose(true).

I'm guessing the problem is with convertToUnixFilesystemPath(), which is called here: https://github.com/testcontainers/testcontainers-java/blob/66e4be2817f82aa80490c21e8df9e8f8a87fa792/core/src/main/java/org/testcontainers/containers/DockerComposeContainer.java#L623. I believe it converts c:\foo\bar to /c/foo/bar.

cer avatar Apr 19 '22 07:04 cer

You are right, this will be the problem. Especially in DockerComposeContainer, it is very hard to take care of all possible environment permutations. Would you like to look into providing a PR?

kiview avatar Apr 19 '22 08:04 kiview

We also just stumbled upon this issue. Has there been some progress on this? Can we do something to help? If there is a snapshot with a fix, we'll be glad to give it a try.

janrieke avatar Jul 22 '22 19:07 janrieke