Add named volumes

Open
#1,564 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
68/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, typescript
Domain
devtools, testing

Research direction

Read packages/testcontainers/src/generic-container/generic-container.ts, then inspect how Network is created, labelled, and disposed, along with the Docker runtime clients under packages/testcontainers/src/container-runtime/clients/. Add the new volume implementation under packages/testcontainers/src/volume/ and builder mount API; check that Ryuk removes session labelled volumes. Done means named volumes can be mounted and disposed with the session lifecycle.

Written by the indexing model from the issue text.

Description

enhancement minor

What happens

Containers can mount host paths (withBindMounts) and tmpfs (withTmpFs). There is no API for named volumes.

  • Sharing data between containers, or keeping data across a container being replaced, needs a host directory.
  • Bind mounts depend on the host filesystem being visible to the Docker daemon, which is not the case for a remote daemon and for some CI setups.
  • withBindMounts([{ source: "my-volume", target: "/data" }]) does create a named volume, because Docker treats a source that is not a path as a volume name. That is undocumented here, and the volume gets no Testcontainers labels, so nothing removes it. stop({ removeVolumes: true }) only removes anonymous volumes.

Expected

  • A Volume with the same lifecycle as Network: created on demand, labelled with the session so it is cleaned up, disposable with await using.
  • withVolumeMounts([{ volume, target, readOnly }]) on the builder.

Where

  • packages/testcontainers/src/generic-container/generic-container.ts
  • a new packages/testcontainers/src/volume/
  • packages/testcontainers/src/container-runtime/clients/

Notes

  • Go has VolumeMount(volumeName, target) next to BindMount, applied with WithMounts.
  • Check that Ryuk removes labelled volumes for the session, as it does containers and networks.

Dependencies

  • Nothing blocks this. It can start now.
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.