testcontainers / testcontainers/testcontainers-java
BrowserWebDriverContainer does not start if shared memory not set under WSL2
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Hi there,
I've been trying to run my UI Tests under Windows out of curiosity. If I use the old Docker engine for Windows, everything works fine (as does under "real" Linux, for that matter). When employing the WSL2 based engine, the tests fail because the container for the web driver (image selenium/standalone-firefox-debug:3.141.59) does not start.
I've been creating the container like so:
private BrowserWebDriverContainer<?> container = new BrowserWebDriverContainer<>()
.withCapabilities(new FirefoxOptions());
If I try to run the tests with WSL 2-based Docker -- no matter if from the IDE or with mvn -- I get the following Exception:
com.github.dockerjava.api.exception.InternalServerErrorException: {"message":"error while creating mount source path '/dev/shm': mkdir /dev/shm: file exists"}
The same happens if I issue docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-firefox from Powershell. It does NOT happen if I issue it under WSL 2's Bash.
FYI: As a workaround, I manually set shared memory on container instantiation:
private BrowserWebDriverContainer<?> container = new BrowserWebDriverContainer<>()
.withSharedMemorySize(2147483648L)
.withCapabilities(new FirefoxOptions());
When preemptively setting shm I can bypass the bind creation in BrowserWebDriverContainer:
if (this.getShmSize() == null) {
this.getBinds().add(new Bind("/dev/shm", new Volume("/dev/shm"), AccessMode.rw));
}
Now, I'm not sure whether this presents as something you can or even want to fix as it seems like it's WSL 2-backed Docker's fault. But here we are. ;)
Besides that, thanks for Testcontainers, it's been nothing but great so far.
Cheers,
rmnbhm
WSL Version: 2
WSL Distro: Ubuntu 18.04
Docker Engine Version: 19.03.8
Windows 10 Version: 2004 (Build 19041.173)
TestContainers Version: 1.12.5
Image used: selenium/standalone-firefox-debug:3.141.59
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with BrowserWebDriverContainer and its shared-memory bind setup, especially the getShmSize() conditional shown in the report. Reproduce the /dev/shm mount failure with WSL2 Docker and the selenium image, then verify the container starts without requiring callers to set shared memory explicitly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100