@Override
    public Boolean call() {
        String address = containerState.getHost();

        externalLivenessCheckPorts
            .parallelStream()
            .forEach(externalPort -> {
                try (Socket socket = new Socket()) {
                    InetSocketAddress inetSocketAddress = new InetSocketAddress(address, externalPort);
                    socket.connect(inetSocketAddress, 1000);
                } catch (IOException e) {
                    throw new IllegalStateException("Socket not listening yet: " + externalPort);
                }
            });
        return true;
    }
Mechanism for testing that a socket is listening when run from the test host.
core/src/main/java/org/testcontainers/containers/wait/internal/ExternalPortListeningCheck.java