Skip to content

[Bug]: Inline env variable doesn't work in "execInContainer" #7651

Description

@gredwhite

Module

Core

Testcontainers version

1.18.3

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host Arch

x64

Docker version

Docker version 24.0.6, build ed223bc

What happened?

In my docker desktop I execute this command successfully:

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

I want to do the same in testcontainers:

SAMBA_IMAGE = "instantlinux/samba-dc:4.18.5-r0"
val sambaContainer = GenericContainer(SAMBA_IMAGE)
....
sambaContainer.execInContainer(
            "LDB_MODULES_PATH=/usr/lib/samba/ldb/",
            "ldbmodify",
            "-H",
           "/var/lib/samba/private/sam.ldb",
            "/tmp/test.ldif",
        )

But 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've found the workaround:

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",
            )

But I still think that my initial attempt should work.

Relevant log output

No response

Additional Information

No response

Activity

  1. eddumelendez commented on Oct 12, 2023

    @eddumelendez
    Member

    I think you may need something like execInContainer("sh", "-c", "the whole command")

    If want to receive more help, please share a reproducible project, it can be a zip file or a github repositoryz
    .

  2. changed the title [-][Bug]: Inline env varibale doesn't work in "execInContainer"[/-] [+][Bug]: Inline env variable doesn't work in "execInContainer"[/+] on Oct 12, 2023
  3. locked and limited conversation to collaborators on Oct 14, 2023
  4. converted this issue into a discussion #7654 on Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions