testcontainers / testcontainers/testcontainers-java

[Bug]: Unable to mount a file from test host into a running container. Using Podman on macOS with x86

Open
#7,241 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

client/podman type/bug
Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

Module

Core

Testcontainers version

1.18.3

Using the latest Testcontainers version?

Yes

Host OS

MacOS Ventura 13.4.1

Host Arch

x86

Docker version
Client:       Podman Engine
Version:      4.5.1
API Version:  4.5.1
Go Version:   go1.20.4
Git Commit:   9eef30051c83f62816a1772a743e5f1271b196d7
Built:        Fri May 26 16:10:12 2023
OS/Arch:      darwin/amd64

Server:       Podman Engine
Version:      4.5.1
API Version:  4.5.1
Go Version:   go1.20.4
Built:        Fri May 26 18:58:48 2
What happened?

Starting a container using Podman run command in terminal I can mount volumes OK. Attempting to do the same in code like:

new GenericContainer<>(imageRepo + ":" + imageTag)
                .withFileSystemBind("./myMount", "/myMount", BindMode.READ_WRITE)
                .withExposedPorts(9080)
                .withPrivilegedMode(true)
                .withLogConsumer(new Slf4jLogConsumer(LOGGER).withPrefix("Service"));
container.start();

Without the withFileSystemBind it starts OK. With it I get this error in log always:

Unable to mount a file from test host into a running container. This may be a misconfiguration or limitation of your Docker environment. Some features might not work.

I can see that in DockerClientFactory method checkMountableFile it attempts to bind a dummy volume and catches any exception. It then only does log.debug of the message including the exception so I can't see the cause.

How can I get the debug output? Does the Slf4jLogConsumer not capture it?

I am using gradle to build and run tests.

Relevant log output
[Test worker] INFO org.testcontainers.dockerclient.DockerClientProviderStrategy - Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
    [Test worker] INFO org.testcontainers.dockerclient.DockerClientProviderStrategy - Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
    [Test worker] INFO org.testcontainers.DockerClientFactory - Docker host IP address is localhost
    [Test worker] INFO org.testcontainers.DockerClientFactory - Connected to docker: 
      Server Version: 4.5.1
      API Version: 1.41
      Operating System: fedora
      Total Memory: 7928 MB
    [Test worker] INFO tc.testcontainers/ryuk:0.5.1 - Creating container for image: testcontainers/ryuk:0.5.1
    [Test worker] INFO tc.testcontainers/ryuk:0.5.1 - Container testcontainers/ryuk:0.5.1 is starting: f6dd9d65d39cdb7749b31b5a9589e8898e3a30022f82534b67243b479327ae63
    [Test worker] INFO tc.testcontainers/ryuk:0.5.1 - Container testcontainers/ryuk:0.5.1 started in PT1.975S
    [Test worker] INFO org.testcontainers.utility.RyukResourceReaper - Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
    [Test worker] INFO org.testcontainers.DockerClientFactory - Checking the system...
    [Test worker] INFO org.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
    [Test worker] INFO tc.myImage:latest - Creating container for image: myImage:latest
    [Test worker] WARN tc.myImage:latest - Unable to mount a file from test host into a running container. This may be a misconfiguration or limitation of your Docker environment. Some features might not work.
Additional Information

testcontainers.properties:

docker.client.strategy=org.testcontainers.dockerclient.UnixSocketClientProviderStrategy
ryuk.container.privileged=true

ls -l /var/run | grep docker:

lrwxr-xr-x  1 root             daemon             61 Jun 27 08:19 docker.sock -> /Users/myUser/.local/share/containers/podman/machine/podman.sock

Podman desktop 1.1.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in DockerClientFactory.checkMountableFile and review how the failed bind-volume check is logged. Compare that path with Slf4jLogConsumer and the Gradle test logging configuration to determine where the underlying exception is available. Done means the mount failure cause can be observed while reproducing the issue with Podman on macOS.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java
Domain
devops, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.