Skip to content

Selenium container not using provided network #844

@GeezFORCE

Description

@GeezFORCE

Encountering this issue when trying expose a host port in compose environment within jest global setup.

Expected Behaviour

Description of the Issue

I am writing a series of tests and as per the previous issue I opened, I was advised to try out jest global setup for creating the environment which can be reused. I moved to jest and was able to migrate most of my test cases.

I am right now trying to integrate some selenium tests into the mix. For this I was utilizing the Selenium Testcontainer module. For using the selenium container, I tried to expose the host ports as shown below and it fails. The port must be exposed and the compose environment must be up, but as soon as the port gets exposed the whole environment exits.

Alternatives Tried
I tried using top-level awaits, waiting for the port to get exposed and then starting the environment to no avail.
I also tried to share the docker compose network to selenium and that too does not seem to work.

Actual Behaviour
Test containers exits just after exposing the port

Testcontainer Logs

testcontainers [DEBUG] Acquiring lock file "/var/folders/1z/mppcm56x179_dq32fmbv89_m0000gn/T/testcontainers-node-sshd.lock"... +0ms
  testcontainers [DEBUG] Acquired lock file "/var/folders/1z/mppcm56x179_dq32fmbv89_m0000gn/T/testcontainers-node-sshd.lock" +2ms
  testcontainers [DEBUG] Checking container runtime strategy "TestcontainersHostStrategy"... +0ms
  testcontainers [DEBUG] Loading ".testcontainers.properties" file... +0ms
  testcontainers [DEBUG] Loaded ".testcontainers.properties" file +1ms
  testcontainers [DEBUG] Found custom configuration: tcHost: "tcp://127.0.0.1:49421", dockerHost: "tcp://127.0.0.1:49421" +1ms
  testcontainers [TRACE] Fetching Docker info... +0ms
  testcontainers [DEBUG] Container runtime strategy "TestcontainersHostStrategy" does not work: "Error: connect ECONNREFUSED 127.0.0.1:49421" +6ms
  testcontainers [DEBUG] Error: connect ECONNREFUSED 127.0.0.1:49421
  testcontainers     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1611:16) +1ms
  testcontainers [DEBUG] Checking container runtime strategy "ConfigurationStrategy"... +0ms
  testcontainers [TRACE] Fetching Docker info... +0ms
  testcontainers [DEBUG] Container runtime strategy "ConfigurationStrategy" does not work: "Error: connect ECONNREFUSED 127.0.0.1:49421" +1ms
  testcontainers [DEBUG] Error: connect ECONNREFUSED 127.0.0.1:49421
  testcontainers     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1611:16) +0ms
  testcontainers [DEBUG] Checking container runtime strategy "UnixSocketStrategy"... +0ms
  testcontainers [DEBUG] Container runtime strategy "UnixSocketStrategy" is not applicable +0ms
  testcontainers [DEBUG] Checking container runtime strategy "RootlessUnixSocketStrategy"... +0ms
  testcontainers [TRACE] Fetching Docker info... +1ms
  testcontainers [TRACE] Fetching remote container runtime socket path... +20ms
  testcontainers [TRACE] Resolving host... +0ms
  testcontainers [TRACE] Fetching Compose info... +0ms
  testcontainers [TRACE] Looking up host IPs... +656ms
  testcontainers [TRACE] Initialising clients... +7ms
  testcontainers [TRACE] Container runtime info:
  testcontainers {
  testcontainers   "node": {
  testcontainers     "version": "v22.9.0",
  testcontainers     "architecture": "arm64",
  testcontainers     "platform": "darwin"
  testcontainers   },
  testcontainers   "containerRuntime": {
  testcontainers     "host": "localhost",
  testcontainers     "hostIps": [
  testcontainers       {
  testcontainers         "address": "::1",
  testcontainers         "family": 6
  testcontainers       },
  testcontainers       {
  testcontainers         "address": "127.0.0.1",
  testcontainers         "family": 4
  testcontainers       }
  testcontainers     ],
  testcontainers     "remoteSocketPath": "/var/run/docker.sock",
  testcontainers     "indexServerAddress": "https://index.docker.io/v1/",
  testcontainers     "serverVersion": "27.2.0",
  testcontainers     "operatingSystem": "Docker Desktop",
  testcontainers     "operatingSystemType": "linux",
  testcontainers     "architecture": "aarch64",
  testcontainers     "cpus": 2,
  testcontainers     "memory": 4112158720,
  testcontainers     "runtimes": [
  testcontainers       "io.containerd.runc.v2",
  testcontainers       "runc"
  testcontainers     ],
  testcontainers     "labels": [
  testcontainers       "com.docker.desktop.address=unix:///Users/user/Library/Containers/com.docker.docker/Data/docker-cli.sock"
  testcontainers     ]
  testcontainers   },
  testcontainers   "compose": {
  testcontainers     "version": "2.29.2-desktop.2",
  testcontainers     "compatability": "v2"
  testcontainers   }
  testcontainers } +0ms
  testcontainers [DEBUG] Container runtime strategy "RootlessUnixSocketStrategy" works +0ms
  testcontainers [DEBUG] Acquiring lock file "/var/folders/1z/mppcm56x179_dq32fmbv89_m0000gn/T/testcontainers-node.lock"... +1ms
  testcontainers [DEBUG] Acquired lock file "/var/folders/1z/mppcm56x179_dq32fmbv89_m0000gn/T/testcontainers-node.lock" +2ms
  testcontainers [DEBUG] Listing containers... +0ms
  testcontainers [DEBUG] Listed containers +6ms
  testcontainers [DEBUG] Creating new Reaper for session "1911d6792f15" with socket path "/var/run/docker.sock"... +1ms
  testcontainers [DEBUG] Checking if image exists "testcontainers/ryuk:0.5.1"... +1ms
  testcontainers [DEBUG] Checked if image exists "testcontainers/ryuk:0.5.1" +4ms
  testcontainers [DEBUG] Image "testcontainers/ryuk:0.5.1" already exists +0ms
  testcontainers [DEBUG] Creating container for image "testcontainers/ryuk:0.5.1"... +1ms
  testcontainers [DEBUG] [8e4f1e007da9] Created container for image "testcontainers/ryuk:0.5.1" +27ms
  testcontainers [INFO] [8e4f1e007da9] Starting container for image "testcontainers/ryuk:0.5.1"... +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Starting container... +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Started container +191ms
  testcontainers [INFO] [8e4f1e007da9] Started container for image "testcontainers/ryuk:0.5.1" +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Inspecting container... +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Inspected container +4ms
  testcontainers [DEBUG] [8e4f1e007da9] Fetching container logs... +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Demuxing stream... +3ms
  testcontainers [DEBUG] [8e4f1e007da9] Demuxed stream +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Fetched container logs +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Waiting for container to be ready... +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Waiting for log message "/.+ Started!/"... +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Fetching container logs... +0ms
  testcontainers:containers [8e4f1e007da9] 2024/10/14 14:34:03 Pinging Docker... +0ms
  testcontainers:containers [8e4f1e007da9] 2024/10/14 14:34:03 Docker daemon is available! +0ms
  testcontainers:containers [8e4f1e007da9] 2024/10/14 14:34:03 Starting on port 8080... +0ms
  testcontainers:containers [8e4f1e007da9] 2024/10/14 14:34:03 Started! +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Demuxing stream... +3ms
  testcontainers [DEBUG] [8e4f1e007da9] Demuxed stream +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Fetched container logs +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Log wait strategy complete +1ms
  testcontainers [INFO] [8e4f1e007da9] Container is ready +1ms
  testcontainers [DEBUG] [8e4f1e007da9] Connecting to Reaper (attempt 1) on "localhost:55223"... +0ms
  testcontainers [DEBUG] [8e4f1e007da9] Connected to Reaper +1ms
  testcontainers [DEBUG] Releasing lock file "/var/folders/1z/mppcm56x179_dq32fmbv89_m0000gn/T/testcontainers-node.lock"... +0ms
  testcontainers [DEBUG] Released lock file "/var/folders/1z/mppcm56x179_dq32fmbv89_m0000gn/T/testcontainers-node.lock" +0ms
  testcontainers [DEBUG] Listing containers... +0ms
  testcontainers:containers [8e4f1e007da9] 2024/10/14 14:34:03 Adding {"label":{"org.testcontainers.session-id=1911d6792f15":true}} +8ms
  testcontainers:containers [8e4f1e007da9] 2024/10/14 14:34:03 New client connected: 192.168.65.1:42759 +0ms
  testcontainers [DEBUG] Listed containers +7ms
  testcontainers [DEBUG] Creating new Port Forwarder... +1ms
  testcontainers [DEBUG] Checking if image exists "testcontainers/sshd:1.2.0"... +0ms
  testcontainers [DEBUG] Checked if image exists "testcontainers/sshd:1.2.0" +2ms
  testcontainers [DEBUG] Image "testcontainers/sshd:1.2.0" already exists +0ms
  testcontainers [DEBUG] Creating container for image "testcontainers/sshd:1.2.0"... +0ms
  testcontainers [DEBUG] [c825d68800a4] Created container for image "testcontainers/sshd:1.2.0" +27ms
  testcontainers [INFO] [c825d68800a4] Starting container for image "testcontainers/sshd:1.2.0"... +0ms
  testcontainers [DEBUG] [c825d68800a4] Starting container... +0ms
  testcontainers [DEBUG] [c825d68800a4] Started container +75ms
  testcontainers [INFO] [c825d68800a4] Started container for image "testcontainers/sshd:1.2.0" +0ms
  testcontainers [DEBUG] [c825d68800a4] Inspecting container... +0ms
  testcontainers [DEBUG] [c825d68800a4] Inspected container +2ms
  testcontainers [DEBUG] [c825d68800a4] Fetching container logs... +0ms
  testcontainers [DEBUG] [c825d68800a4] Demuxing stream... +1ms
  testcontainers [DEBUG] [c825d68800a4] Demuxed stream +1ms
  testcontainers [DEBUG] [c825d68800a4] Fetched container logs +0ms
  testcontainers [DEBUG] [c825d68800a4] Waiting for container to be ready... +0ms
  testcontainers [DEBUG] [c825d68800a4] Waiting for host port 55224... +0ms
  testcontainers [DEBUG] [c825d68800a4] Waiting for internal port 22... +0ms
  testcontainers [DEBUG] [c825d68800a4] Host port 55224 ready +1ms
  testcontainers [DEBUG] [c825d68800a4] Host port wait strategy complete +0ms
  testcontainers:containers [c825d68800a4] chpasswd: password for 'root' changed +115ms
  testcontainers [DEBUG] [c825d68800a4] Internal port 22 ready +33ms
  testcontainers [INFO] [c825d68800a4] Container is ready +0ms
  testcontainers [DEBUG] Connecting to Port Forwarder on "localhost:55224"... +0ms
  testcontainers [DEBUG] Connected to Port Forwarder on "localhost:55224" +34ms
  testcontainers [DEBUG] Releasing lock file "/var/folders/1z/mppcm56x179_dq32fmbv89_m0000gn/T/testcontainers-node-sshd.lock"... +0ms
  testcontainers [DEBUG] Released lock file "/var/folders/1z/mppcm56x179_dq32fmbv89_m0000gn/T/testcontainers-node-sshd.lock" +0ms
  testcontainers [INFO] Exposing host port 80... +0ms

Process finished with exit code 0

Steps to Reproduce

  1. Start a compose environment along with exposing port as part of jest's global setup.
// Jest Global Setup File
import {DockerComposeEnvironment, log, TestContainers, Wait} from "testcontainers";

module.exports = async () => {
    try {
        await TestContainers.exposeHostPorts(80)
        global.environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
                    .withWaitStrategy("testcontainer1", Wait.forHealthCheck())
                    .withWaitStrategy("testcontainer2", Wait.forLogMessage(/Server started at/))
                    .withNoRecreate()
                    .up();
    } catch (e) {
        log.error(e);
    }
};

Environment Information

  • Operating System: MacOS v 15.0.1 (M1)
  • Docker Version: 27.2.0, build 3ab4256
  • Node version: 22.9.0
  • Testcontainers version: 10.13.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions