testcontainers / testcontainers-java

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.org
MIT License
8k stars 1.64k forks source link

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

Open JDUNNIN opened 1 year ago

JDUNNIN commented 1 year ago

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

JDUNNIN commented 1 year ago

Tried using different Podman machines with commands to see if the mount into the machine was causing an issue:

 podman machine init --rootful -v /Users/myUser:$HOME --memory 8192 --cpus 4  

and

podman machine init --rootful --memory 8192 --cpus 4 
Saimurugeshwari commented 1 year ago

I would like to contribute, kindly assign

jcjolley commented 2 weeks ago

I get this as well