You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current C API is quite complicated for consumption. It would be great to have a C++ binding with better developer experience for C/C++ users.
Namespace
Proper Structures
TBD: Classes
Possible implementations
A single-header C++ library. The class structure can be inspired by the Rust or Java implementation. Java is a reference implementation, so the structure could be considered as a North Star for us
Maybe: Java API export to C++ bindings boilerplate
Creating a new official Docker client for C++, and rebuilding a Testcontainers impl from Scrath => XXXXXL sized project
? Connecting to another implementation over API
C++ Standard: TBD but something relatively recent
TODOs
Define the approximate architecture of the API
First PoC
Include C/C++ binding into the distros and get a preview
Hi, I wanted to use this library in my project, but I discovered that cgo has extremely poor cross-platform support, which is unsuitable for a public C++ library. So I decided to try a similar approach, but using rust, testcontainers-rs, and cxx, which have much better cross-platform support and CMake integration. I already have a project skeleton, and overall, C++ compatibility is quite good. The interface looks something like this::
TEST(RedisTest, StartAndGetMappedPort) {
auto container = GenericImage("redis", "7.2")
.with_exposed_port(ContainerPort::Tcp(6379))
.with_wait_for(WaitFor::message_on_stdout("Ready to accept connections"))
.with_health_check(Healthcheck::Cmd({"redis-cli", "ping"}).with_interval(std::chrono::seconds(1)))
.start();
auto host_port = container.get_host_port_ipv4(ContainerPort::Tcp(6379));
EXPECT_GT(host_port, 0);
std::cout << "Redis mapped port: " << host_port << std::endl;
// Container will be auto-cleaned when it goes out of scope
}
For what it's worth, I tried setting up to use TestContainers in a C++ project today, not realizing it's incomplete (Gemini hallucinated how to use it, apparently). I brought it in using CMake FetchContent, which led to the compiler error I put a PR in for. But now, looking at the Container and Builder interfaces, I don't see how I should wait-until or trigger-code-when the service is running in the container, nor how to get the endpoint to use in a call to a constructor for a Redis object. Are these things in the works? If so, how long do you think it might be before they are ready? If not, does someone have an example sitting around that you're testing with?
Activity
miltoncs commentedon Aug 28, 2024
Big fan of test containers, I'm excited for the C++ library to be production ready!
cppudge commentedon Nov 9, 2025
Hi, I wanted to use this library in my project, but I discovered that cgo has extremely poor cross-platform support, which is unsuitable for a public C++ library. So I decided to try a similar approach, but using rust, testcontainers-rs, and cxx, which have much better cross-platform support and CMake integration. I already have a project skeleton, and overall, C++ compatibility is quite good. The interface looks something like this::
oleg-nenashev commentedon May 31, 2026
#54 from @seffradev gets us very close to completing it. Before the the release, we need to update the docs in https://testcontainers.github.io/testcontainers-native/docs/cpp/ , and to cleanup a few other examples. I will try to test the changes in the main over the next 1-2 weeks
mplumleeUNH commentedon Jun 8, 2026
For what it's worth, I tried setting up to use TestContainers in a C++ project today, not realizing it's incomplete (Gemini hallucinated how to use it, apparently). I brought it in using CMake FetchContent, which led to the compiler error I put a PR in for. But now, looking at the Container and Builder interfaces, I don't see how I should wait-until or trigger-code-when the service is running in the container, nor how to get the endpoint to use in a call to a constructor for a Redis object. Are these things in the works? If so, how long do you think it might be before they are ready? If not, does someone have an example sitting around that you're testing with?
oleg-nenashev commentedon Jun 8, 2026
The C++ lib definitely needs more work before we can call it ready (basically this whole repo is pre-1.0 and needs more work).
Thanks for the PR addressing some of the problems. We definitely need a smoke test and a demo for FetchContent so that it does not explode.