Add an escape hatch for raw container create options

Open
#1,550 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, typescript
Domain
backend, devtools

Research direction

Read packages/testcontainers/src/generic-container/generic-container.ts and packages/testcontainers/src/test-container.ts, then trace where start() builds the Docker create request. Add the documented builder modifier so it runs last and works for modules; account for its output in the reuse hash as required by #1522, coordinating with #1520. Done when the modifier can set raw create options and the reuse hash reflects them.

Written by the indexing model from the issue text.

Description

enhancement minor

What happens

A Docker create option that has no with* method can only be set by subclassing GenericContainer and writing to the protected createOpts or hostConfig:

class SysctlContainer extends GenericContainer {
  constructor(image: string) {
    super(image);
    this.hostConfig.Sysctls = { "net.core.somaxconn": "1024" };
  }
}

Options in this position today include Sysctls, Dns, Devices, ReadonlyRootfs, RestartPolicy, Init, PidMode and StopSignal. Each one otherwise needs a feature request and a release.

It also cannot be done for a module container without subclassing the module.

Expected

A documented escape hatch on the builder:

new GenericContainer(image).withCreateOptions((options) => {
  options.HostConfig.Sysctls = { "net.core.somaxconn": "1024" };
});

It runs last, after the library has built the request, and works on any container including modules.

Where

  • packages/testcontainers/src/generic-container/generic-container.ts
  • packages/testcontainers/src/test-container.ts

Notes

  • Java has withCreateContainerCmdModifier(Consumer<CreateContainerCmd>). Go has ConfigModifier, HostConfigModifier and EndpointSettingsModifier on the request, and has deprecated several dedicated fields in their favour.
  • This exposes Dockerode's types on purpose, in one clearly marked place. With an escape hatch, subclasses no longer need the protected createOpts and hostConfig fields.
  • The modifier's result must be part of the reuse hash (#1522).

Dependencies

  • Stack on #1520: the modifier runs where start() builds the create request, which that issue reworks.
  • Coordinate with #1522: the modifier's output has to be part of the reuse hash.
Dominant language
TypeScript
Stars
2.7k
Forks
290
Avg merge
4d 1h
Merged PRs (30d)
22

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testcontainers/testcontainers-node

All issues in testcontainers/testcontainers-node

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.