Skip to content

DevNatan/docker-kotlin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e1836c4 · Feb 4, 2024
Aug 5, 2023
Aug 18, 2023
Dec 4, 2022
Sep 11, 2023
Feb 4, 2024
Dec 4, 2022
Dec 23, 2021
Jan 9, 2022
Feb 4, 2024
Aug 17, 2023
Aug 17, 2023
Feb 4, 2024
Aug 5, 2023
Dec 4, 2022
Dec 21, 2021
Apr 24, 2023

Repository files navigation

Yoki logo

Yoki

Build Integration Tests Maven Central

Yoki allows you to interact with the Docker Engine Remote API in a simplified and fast way.

repositories {
    mavenCentral()
}

dependencies {
    implementation("me.devnatan:yoki:0.3.0")
}

For Java users, use the Yoki JVM artifact

implementation 'me.devnatan:yoki-jvm:0.3.0'

Getting Started

Use Yoki.create() to create a new Yoki 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 = Yoki.create()

To change the default configuration properties use YokiConfig and Yoki overload.

val client = Yoki {
    // this: YokiConfigBuilder
}

In Java code you can use YokiConfigBuilder with YokiConfig.builder().

YokiConfig config = YokiConfig.builder().socketPath(...).build()
Yoki client = Yoki.create(config)

To Docker resources, functions will return CompletableFuture<T> or YokiFlow<T> (for streaming) due to Java Interoperatibility but there are extensions for Kotlin that are suspend and for streaming returns Flow<T>.

Get System Information
val version: SystemVersion = client.system.version()
List All Containers
val containers: List<Container> = client.containers.list()
Create a new Network
val networkId: String = client.networks.create {
    name = "octopus-net"
    driver = "overlay"
}
Stream Container Logs
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 */ }
final YokiFlow<Frame> callback = new YokiFlow<Frame>() {
    @Override
    public void onEach(Frame log) { /* do something with each log */ }

    @Override
    public void onStart() { /* streaming started */ }

    @Override
    public void onComplete(Throwable error) { /* streaming finished */ }
    
    @Override
    public void onError(Throwable cause) { /* something went wrong */ }
};

client.containers.logsAsync("floral-fury", callback);

// Short version
client.containers.logsAsync("floral-fury", (log) -> /* do something with each log */);

License

Yoki is licensed under the MIT license.