Skip to content

Add named volumes #1564

Open
Open

Description

@cristianrgreco

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.

Activity

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 requestminorBackward compatible functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions