Skip to content

[Bug]: MongoDB withReuse and withReplica keeps on trying to execute command without ever resolving #1722

Description

@Younanator

Testcontainers version

4.11.0

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host arch

x86

.NET version

10

Docker version

Docker version 28.3.2, build 578ccf6

Docker info

Client:
 Version:    28.3.2
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  ai: Docker AI Agent - Ask Gordon (Docker Inc.)
    Version:  v1.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-ai.exe
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.25.0-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  cloud: Docker Cloud (Docker Inc.)
    Version:  v0.4.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-cloud.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.38.2-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.41
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  desktop: Docker Desktop commands (Docker Inc.)
    Version:  v0.1.11
    Path:     C:\Program Files\Docker\cli-plugins\docker-desktop.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.29
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  mcp: Docker MCP Plugin (Docker Inc.)
    Version:  v0.9.9
    Path:     C:\Program Files\Docker\cli-plugins\docker-mcp.exe
  model: Docker Model Runner (EXPERIMENTAL) (Docker Inc.)
    Version:  v0.1.33
    Path:     C:\Program Files\Docker\cli-plugins\docker-model.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.18.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 52
  Running: 36
  Paused: 0
  Stopped: 16
 Images: 31
 Server Version: 28.3.2
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Discovered Devices:
  cdi: docker.com/gpu=webgpu
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.18.33.2-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 11.68GiB
 Name: docker-desktop
 ID: be00c36c-63ee-4759-8d9d-a0ca5b0d5544
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=npipe://\\.\pipe\docker_cli
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: DOCKER_INSECURE_NO_IPTABLES_RAW is set

What happened?

It will keep trying to execute this command when withReuse and withReplica are used.

Works fine when withReuse is disabled, and also works fine on initial creation of container, but fails on subsequent initializations as container exists.

Container = new MongoDbBuilder("mongo:latest") .WithReuse(true) .WithReplicaSet("rs1") .Build();

Relevant log output

807/chphnelc.5jr')" at Docker container ab0d91582101
[testcontainers.org 00:00:24.25] Add file to tar archive: Content length: 91 byte(s), Target file: "/tmp/3af0288c-0a04-4172-8e7f-7ab2552da676/nrb3qtyo.ilh", UID: 0, GID: 0, Mode: 0644
[testcontainers.org 00:00:24.25] Copy tar archive to container: Content length: 91 byte(s), Docker container: ab0d91582101
[testcontainers.org 00:00:24.26] Execute "which mongosh" at Docker container ab0d91582101
[testcontainers.org 00:00:24.33] Execute "mongosh --username testuser --password testpassword --quiet --eval load('/tmp/3af0288c-0a04-4172-8e7f-7ab2552da676/nrb3qtyo.ilh')" at Docker container ab0d91582101
[testcontainers.org 00:00:25.85] Add file to tar archive: Content length: 91 byte(s), Target file: "/tmp/33345c51-426a-4482-8964-4109a7468342/yi54xdjz.xcc", UID: 0, GID: 0, Mode: 0644
[testcontainers.org 00:00:25.85] Copy tar archive to container: Content length: 91 byte(s), Docker container: ab0d91582101
[testcontainers.org 00:00:25.86] Execute "which mongosh" at Docker container ab0d91582101
[testcontainers.org 00:00:25.93] Execute "mongosh --username testuser --password testpassword --quiet --eval load('/tmp/33345c51-426a-4482-8964-4109a7468342/yi54xdjz.xcc')" at Docker container ab0d91582101
[testcontainers.org 00:00:27.39] Add file to tar archive: Content length: 91 byte(s), Target file: "/tmp/41cf4b71-711c-463e-ab22-c7ac0157e025/fqd1v5sh.evn", UID: 0, GID: 0, Mode: 0644
[testcontainers.org 00:00:27.39] Copy tar archive to container: Content length: 91 byte(s), Docker container: ab0d91582101
[testcontainers.org 00:00:27.40] Execute "which mongosh" at Docker container ab0d91582101
[testcontainers.org 00:00:27.48] Execute "mongosh --username testuser --password testpassword --quiet --eval load('/tmp/41cf4b71-711c-463e-ab22-c7ac0157e025/fqd1v5sh.evn')" at Docker container ab0d91582101

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmoduleAn official Testcontainers module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions