Skip to content

Avoid duplicate /dev/shm bind when reusing BrowserWebDriverContainer#11945

Open
kdelay wants to merge 2 commits into
testcontainers:mainfrom
kdelay:fix/issue-11941-selenium-shm-reuse
Open

Avoid duplicate /dev/shm bind when reusing BrowserWebDriverContainer#11945
kdelay wants to merge 2 commits into
testcontainers:mainfrom
kdelay:fix/issue-11941-selenium-shm-reuse

Conversation

@kdelay

@kdelay kdelay commented Jul 24, 2026

Copy link
Copy Markdown

What

Reusing a BrowserWebDriverContainer (stop, then start again) fails on Linux with:

com.github.dockerjava.api.exception.BadRequestException: Status 400: {"message":"Duplicate mount point: /dev/shm"}

Why

configure() runs on every start(). On non-Windows hosts it appended a /dev/shm bind to the container binds unconditionally. When the same container instance is started more than once (reuse), the bind was added again, producing a duplicate mount point that Docker rejects at create time.

Change

Only add the /dev/shm bind when one is not already present. Applied to both the org.testcontainers.selenium.BrowserWebDriverContainer and its deprecated org.testcontainers.containers.BrowserWebDriverContainer counterpart, which shared the same logic.

Verification

Added BrowserWebDriverContainerReuseTest which calls configure() twice (as a reused container would) and asserts a single /dev/shm bind. It fails on the current code (2 binds) and passes with this change. No Docker daemon is required for the test, as it only exercises the container configuration.

./gradlew :testcontainers-selenium:spotlessCheck :testcontainers-selenium:compileJava :testcontainers-selenium:test --tests "org.testcontainers.selenium.BrowserWebDriverContainerReuseTest" is green.

Fixes #11941

configure() runs on every start(), and on non-Windows hosts it
unconditionally appended a /dev/shm bind to the container binds. When a
BrowserWebDriverContainer is stopped and started again (reuse), the bind
was added a second time, so container creation failed with
"Status 400: Duplicate mount point: /dev/shm".

Only add the /dev/shm bind if one is not already present, in both the
selenium module container and its deprecated counterpart.

Fixes testcontainers#11941

Signed-off-by: kdelay <kdelay20@gmail.com>
@kdelay
kdelay requested a review from a team as a code owner July 24, 2026 00:14
@duoduobingbing

duoduobingbing commented Jul 24, 2026

Copy link
Copy Markdown

@kdelay Doesn't that test need a safeguard so that it does not run on Windows. E.g. JUnit's @DisabledOnOs(OS.WINDOWS) at the test?

The Windows branch of configure() does not add the /dev/shm bind, so the
test asserting exactly one /dev/shm bind after two configure() calls would
fail on Windows. Guard it with @DisabledOnOs(OS.WINDOWS).
@kdelay

kdelay commented Jul 24, 2026

Copy link
Copy Markdown
Author

Good catch, thanks. Done in f66bd9e - added @DisabledOnOs(OS.WINDOWS) to the test, since the Windows branch of configure() does not add the /dev/shm bind and the assertion would otherwise fail there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot reuse Selenium BrowserWebDriverContainers under Linux

2 participants