Skip to content

Add C++ binding library #12

Open

Description

@oleg-nenashev

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

  1. 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
  1. Creating a new official Docker client for C++, and rebuilding a Testcontainers impl from Scrath => XXXXXL sized project
  2. ? 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
  • More tests and demos
  • Update documentation

Activity

  1. miltoncs commented on Aug 28, 2024

    @miltoncs

    Big fan of test containers, I'm excited for the C++ library to be production ready!

  2. cppudge commented on Nov 9, 2025

    @cppudge

    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
    }
  3. added this to the 1.0 milestone on May 31, 2026
  4. oleg-nenashev commented on May 31, 2026

    @oleg-nenashev
    CollaboratorAuthor

    #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

  5. mplumleeUNH commented on Jun 8, 2026

    @mplumleeUNH
    Contributor

    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?

  6. oleg-nenashev commented on Jun 8, 2026

    @oleg-nenashev
    CollaboratorAuthor

    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.

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions