
Docker Remote API client featuring type-safe OpenAPI-generated models, async streaming of logs/stats, Unix domain socket connectivity, and DSL-style management for containers, images, networks, volumes.
A Docker Remote API client library written in Kotlin Multiplatform using Ktor.
/var/run/docker.sock.Add dependency to your build.gradle.kts:
dependencies {
implementation("dev.limebeck.libs:docker-client:0.0.5")
}By default, the client is configured to connect via the local Unix socket:
val dockerClient = DockerClient()Custom configuration using DockerClientConfig:
val config = DockerClientConfig(
json = Json { ignoreUnknownKeys = true },
connectionConfig = DockerClientConfig.ConnectionConfig.SocketConnection("/var/run/docker.sock"),
)
val dockerClient = DockerClient(config)The library provides a DSL-like access to various parts of the Docker API.
val containers = dockerClient.containers.getList().getOrNull()
containers?.forEach { println(it.names) }val createdContainer = dockerClient.containers.create(
name = "my-container",
config = ContainerConfig(
image = "bash",
cmd = listOf("-c", "while true; do date; sleep 2; done")
)
).getOrThrow()
dockerClient.containers.start(createdContainer.id).getOrThrow()val logsFlow = dockerClient.containers.getLogs(
id = createdContainer.id,
parameters = ContainerLogsParameters(
follow = true,
stdout = true,
stderr = true
)
).getOrThrow()
logsFlow.collect { logLine ->
println("${logLine.type}: ${logLine.line}")
}If you need to use an endpoint that is not yet implemented, you can easily extend the client:
val DockerClient.myCustomApi by ::MyCustom.api()
class MyCustom(val dockerClient: DockerClient) {
suspend fun getCustomInfo(): Result<MyCustomResponse, ErrorResponse> = with(dockerClient) {
return client.get("/my/custom/endpoint").parse()
}
}lib: The main module containing the Docker client implementation and generated models.specs: Contains the Docker API OpenAPI specification.sample/terminalApp: A sample console application using the library.sample/htmxDashboard: A sample web dashboard using Ktor and HTMX to monitor containers.Terminal App:
./gradlew :sample:terminalApp:runDebugExecutableLinuxX64HTMX Dashboard:
./gradlew :sample:htmxDashboard:runDebugExecutableLinuxX64The project uses OpenAPI Generator to create data models. When building the project, models are automatically generated into the lib/build/generated/openapi directory.
To build the project:
./gradlew buildContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License β see the LICENSE file for details.
A Docker Remote API client library written in Kotlin Multiplatform using Ktor.
/var/run/docker.sock.Add dependency to your build.gradle.kts:
dependencies {
implementation("dev.limebeck.libs:docker-client:0.0.5")
}By default, the client is configured to connect via the local Unix socket:
val dockerClient = DockerClient()Custom configuration using DockerClientConfig:
val config = DockerClientConfig(
json = Json { ignoreUnknownKeys = true },
connectionConfig = DockerClientConfig.ConnectionConfig.SocketConnection("/var/run/docker.sock"),
)
val dockerClient = DockerClient(config)The library provides a DSL-like access to various parts of the Docker API.
val containers = dockerClient.containers.getList().getOrNull()
containers?.forEach { println(it.names) }val createdContainer = dockerClient.containers.create(
name = "my-container",
config = ContainerConfig(
image = "bash",
cmd = listOf("-c", "while true; do date; sleep 2; done")
)
).getOrThrow()
dockerClient.containers.start(createdContainer.id).getOrThrow()val logsFlow = dockerClient.containers.getLogs(
id = createdContainer.id,
parameters = ContainerLogsParameters(
follow = true,
stdout = true,
stderr = true
)
).getOrThrow()
logsFlow.collect { logLine ->
println("${logLine.type}: ${logLine.line}")
}If you need to use an endpoint that is not yet implemented, you can easily extend the client:
val DockerClient.myCustomApi by ::MyCustom.api()
class MyCustom(val dockerClient: DockerClient) {
suspend fun getCustomInfo(): Result<MyCustomResponse, ErrorResponse> = with(dockerClient) {
return client.get("/my/custom/endpoint").parse()
}
}lib: The main module containing the Docker client implementation and generated models.specs: Contains the Docker API OpenAPI specification.sample/terminalApp: A sample console application using the library.sample/htmxDashboard: A sample web dashboard using Ktor and HTMX to monitor containers.Terminal App:
./gradlew :sample:terminalApp:runDebugExecutableLinuxX64HTMX Dashboard:
./gradlew :sample:htmxDashboard:runDebugExecutableLinuxX64The project uses OpenAPI Generator to create data models. When building the project, models are automatically generated into the lib/build/generated/openapi directory.
To build the project:
./gradlew buildContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License β see the LICENSE file for details.