javabashcmdsambatestcontainers

How to execute cmd command in the container up with TestContainers?


I can execute command (inside the container started with testcontainers) from cmd. I want to execute the same comamnd from testcontainers api

/ # LDB_MODULES_PATH=/usr/lib/samba/ldb/ ldbmodify -H /var/lib/samba/private/sam.ldb /tmp/test.ldif 
Modified 0 records successfully

enter image description here

option1:

sambaContainer.execInContainer(
            "LDB_MODULES_PATH=/usr/lib/samba/ldb/",
            "ldbmodify",
            "-H",
           "/var/lib/samba/private/sam.ldb",
            "/tmp/test.ldif",
        )

I get the error:

OCI runtime exec failed: exec failed: unable to start container process: exec: "LDB_MODULES_PATH=/usr/lib/samba/ldb/": stat LDB_MODULES_PATH=/usr/lib/samba/ldb/: no such file or directory: unknown

I tried 2 options:

option 2:

sambaContainer
            .withEnv("LDB_MODULES_PATH","/usr/lib/samba/ldb/" )
            .execInContainer(
            "ldbmodify",
            "-H",
           "/var/lib/samba/private/sam.ldb",
            "/tmp/test.ldif",
        )

I get the error:

WARNING: Module [samba_dsdb] not found - do you need to set LDB_MODULES_PATH?
Unable to load modules for /var/lib/samba/private/sam.ldb: (null)
Failed to connect to /var/lib/samba/private/sam.ldb - (null)

Result of the second option is the same as executing

ldbmodify -H /var/lib/samba/private/sam.ldb /tmp/test.ldif

from cmd:

enter image description here

How to execute the command from testContainers ?


Solution

  • This works:

    val sambaContainer = GenericContainer(SAMBA_IMAGE)
                         ...
                        .withEnv("LDB_MODULES_PATH","/usr/lib/samba/ldb/")
    sambaContainer.start()
    sambaContainer.execInContainer(
                    "ldbmodify",
                    "-H",
                   "/var/lib/samba/private/sam.ldb",
                    "/tmp/test.ldif",
                )