Skip to content

Unable to connect to the NodeJS NATS testcontainer #1008

@jdinsel-xealth

Description

@jdinsel-xealth

Expected Behaviour

The example NATS testcontainer should be able to connect.

Actual Behaviour

An error is always returned:

Error connecting to NATS: ConnectionError: connection refused

Testcontainer Logs

  console.log
      testcontainers:containers [f9e8f3a898be] time=2025-05-21T18:27:35.529Z level=INFO msg=starting connection_timeout=1m0s reconnection_timeout=10s request_timeout=10s shutdown_timeout=10m0s remove_retries=10 retry_offset=-1s changes_retry_interval=1s port=8080 verbose=false +0ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [f9e8f3a898be] time=2025-05-21T18:27:35.529Z level=INFO msg=Started address=[::]:8080 +14ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [f9e8f3a898be] time=2025-05-21T18:27:35.529Z level=INFO msg="client processing started" +0ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [f9e8f3a898be] time=2025-05-21T18:27:36.554Z level=INFO msg="client connected" address=172.17.0.1:46164 clients=1 +1s

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [f9e8f3a898be] time=2025-05-21T18:27:36.554Z level=INFO msg="adding filter" type=label values="[org.testcontainers.session-id=194a9424e34a]" +0ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [fa463d4bde4d] [1] 2025/05/21 18:27:36.876320 [INF] Starting nats-server +322ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [fa463d4bde4d] [1] 2025/05/21 18:27:36.876407 [INF]   Version:  2.8.4 +0ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [fa463d4bde4d] [1] 2025/05/21 18:27:36.876409 [INF]   Git:      [66524ed] +0ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [fa463d4bde4d] [1] 2025/05/21 18:27:36.876411 [INF]   Name:     NDO6YNLKKQD7AF2YCUGDL7WUBQMHWS4ADWQKMQU2XZ6BOZMA7WVEXGNH +1ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [fa463d4bde4d] [1] 2025/05/21 18:27:36.876413 [INF]   ID:       NDO6YNLKKQD7AF2YCUGDL7WUBQMHWS4ADWQKMQU2XZ6BOZMA7WVEXGNH +1ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [fa463d4bde4d] [1] 2025/05/21 18:27:36.876420 [WRN] Plaintext passwords detected, use nkeys or bcrypt +0ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [fa463d4bde4d] [1] 2025/05/21 18:27:36.877187 [INF] Listening for client connections on 0.0.0.0:4222 +2ms

      at Logger.debug [as logger] (../node_modules/debug/src/common.js:113:10)

  console.log
      testcontainers:containers [fa463d4bde4d] [1] 2025/05/21 18:27:36.877312 [INF] Server is ready +1ms

Steps to Reproduce

  1. Use the steps documented for the NodeJS NATS container
  2. Use @nats-io/transport-node for the connect method
  3. Execute the test
  4. See the error above

Environment Information

  • Operating System: MacOS 15.5
  • Docker Version: 26.1.5
  • Node version: v22.15.0
  • Testcontainers version: 10.27.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageInvestigation required

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions