Skip to content

Can Testcontainers itself be used from inside a container? #423

Answered by HofmeisterAn
jernejg asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, sibling containers are working. The ResourceReaper use it as well. Following example incl. running the default ResourceReaper in the background works fine:

var testcontainers = new TestcontainersBuilder<TestcontainersContainer>()
  .WithImage("docker")
  .WithCommand(KeepTestcontainersUpAndRunning.Command)
  .WithBindMount("/var/run/docker.sock", "/var/run/docker.sock", AccessMode.ReadOnly)
  .Build();

await testcontainers.StartAsync()
  .ConfigureAwait(false);

var execResult = await testcontainers.ExecAsync(new[] { "docker", "ps" })
  .ConfigureAwait(false);

execResult contains the sibling containers:

CONTAINER ID   IMAGE                              COMMAND                  CREAT…

Replies: 2 comments 30 replies

Comment options

You must be logged in to vote
1 reply
@HofmeisterAn
Comment options

Comment options

You must be logged in to vote
29 replies
@HofmeisterAn
Comment options

@PSanetra
Comment options

@HofmeisterAn
Comment options

@PSanetra
Comment options

Answer selected by HofmeisterAn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants