startInteractive

suspend fun startInteractive(id: String, consoleSize: Pair<Int, Int>? = null): Result<ExecSession, ErrorResponse>

Starts a previously created exec instance and returns an independently owned ExecSession. Match the TTY mode used at creation; the overload without tty uses true. Collect one output flow once. Use incomingChunks for terminal bytes and incremental UTF-8 decoding. Close the session when finished, including when output is never collected.

Transport and non-HTTP handshake failures throw their original exception; read dev.limebeck.libs.docker.client.diagnostics.dockerContext for safe operation details. Cancellation propagates. Output and send failures can also occur after this method returns.

Return

Owned interactive session, or a daemon HTTP error response.

Parameters

id

Exec instance ID returned by Containers.execCreate.

consoleSize

Initial TTY dimensions as rows to columns; null leaves Docker defaults.

See also

Samples

val execId = docker.containers.execCreate(containerId, ExecConfig(
    cmd = listOf("/bin/sh"), tty = true,
    attachStdin = true, attachStdout = true, attachStderr = true,
)).getOrThrow().id
docker.exec.startInteractive(execId, tty = true).getOrThrow().use { session ->
    coroutineScope {
        val sender = launch {
            try { input.collect { session.send(it) } }
            finally { session.close() }
        }
        try {
            docker.exec.resize(execId, h = 24, w = 80).getOrThrow()
            session.incomingChunks.collect { output(it.bytes) }
        } finally {
            sender.cancelAndJoin()
        }
    }
}

suspend fun startInteractive(id: String, consoleSize: Pair<Int, Int>? = null, tty: Boolean): Result<ExecSession, ErrorResponse>

Starts a previously created exec instance and returns an independently owned ExecSession. Match the TTY mode used at creation; the overload without tty uses true. Collect one output flow once. Use incomingChunks for terminal bytes and incremental UTF-8 decoding. Close the session when finished, including when output is never collected.

Transport and non-HTTP handshake failures throw their original exception; read dev.limebeck.libs.docker.client.diagnostics.dockerContext for safe operation details. Cancellation propagates. Output and send failures can also occur after this method returns.

Return

Owned interactive session, or a daemon HTTP error response.

Parameters

id

Exec instance ID returned by Containers.execCreate.

consoleSize

Initial TTY dimensions as rows to columns; null leaves Docker defaults.

tty

TTY mode matching the original exec configuration.

See also

Samples

val execId = docker.containers.execCreate(containerId, ExecConfig(
    cmd = listOf("/bin/sh"), tty = true,
    attachStdin = true, attachStdout = true, attachStderr = true,
)).getOrThrow().id
docker.exec.startInteractive(execId, tty = true).getOrThrow().use { session ->
    coroutineScope {
        val sender = launch {
            try { input.collect { session.send(it) } }
            finally { session.close() }
        }
        try {
            docker.exec.resize(execId, h = 24, w = 80).getOrThrow()
            session.incomingChunks.collect { output(it.bytes) }
        } finally {
            sender.cancelAndJoin()
        }
    }
}