docker-kotlin allows you to interact with the Docker Engine Remote API in a simplified and fast way.
repositories {
mavenCentral()
}
dependencies {
implementation("me.devnatan:docker-kotlin:0.6.0")
}
For JVM users, use the Docker client JVM artifact
implementation 'me.devnatan:docker-kotlin-jvm:0.6.0'
Use DockerKotlin.create()
to create a new Docker client instance with the default settings, default settings are based on the
current platform or environment variables, e.g.: socket path will be set to DOCKER_HOST
if present otherwise unix://var/run/docker.sock
if the current platform is Unix-like.
val client = DockerClient.create()
To change the default configuration properties use DockerClientConfig
and DockerClient
overload.
val client = DockerClient {
// this: DockerClientConfigBuilder
}
val version: SystemVersion = client.system.version()
val containerId = client.containers.create("busybox:latest") {
// Only if your container doesn't already expose this port
exposedPort(80u)
hostConfig {
portBindings(80u) {
add(PortBinding("0.0.0.0", 8080u))
}
}
}
client.containers.start(containerId)
val containerId = client.containers.create("busybox:latest") {
// Only if your container doesn't already expose this port
exposedPort(80u)
hostConfig {
portBindings(80u)
}
}
client.containers.start(containerId)
// Inspect the container to retrieve the auto-assigned ports
val container = testClient.containers.inspect(id)
val ports = container.networkSettings.ports
val containers: List<Container> = client.containers.list()
val networkId: String = client.networks.create {
name = "octopus-net"
driver = "overlay"
}
val logs: Flow<Frame> = client.containers.logs("floral-fury") {
stderr = true
stdout = true
}
logs.onStart { /* streaming started */ }
.onCompletion { /* streaming finished */ }
.catch { /* something went wrong */ }
.collect { log -> /* do something with each log */ }
docker-kotlin is licensed under the MIT license.