Is this for WSL1 and/or WSL2: Windows Support -> Windows Subsystem for Linux (WSL) -> Optional - Only if volumes are required:
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.
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?
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
Does it work correctly if you use docker-compose directly?
Does it work correctly if you use docker-compose directly?
Yes.
Does it work correctly if you configure DockerComposeContainer using withLocal(true)?
Unsure. my Windows machine is running Docker Compose 2 so I've been using withLocal(false)
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.
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.
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?
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.