{"id":15568348,"url":"https://github.com/devnatan/docker-kotlin","last_synced_at":"2026-02-15T04:03:11.164Z","repository":{"id":36974597,"uuid":"392883613","full_name":"devnatan/docker-kotlin","owner":"devnatan","description":"Docker Engine Remote API client","archived":false,"fork":false,"pushed_at":"2026-01-28T15:21:43.000Z","size":1106,"stargazers_count":29,"open_issues_count":11,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-01-29T06:49:51.605Z","etag":null,"topics":["api","client","docker","docker-kotlin","engine","java","jvm","kotlin","multiplatform"],"latest_commit_sha":null,"homepage":"https://docs.devnatan.me/docker-kotlin","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devnatan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"SUPPORTED_ENDPOINTS.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-08-05T02:51:17.000Z","updated_at":"2026-01-28T15:31:24.000Z","dependencies_parsed_at":"2024-02-04T02:29:53.402Z","dependency_job_id":"22aba4c0-632d-4689-ae4d-8306cb87c81d","html_url":"https://github.com/devnatan/docker-kotlin","commit_stats":null,"previous_names":["devnatan/docker-kotlin"],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/devnatan/docker-kotlin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnatan%2Fdocker-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnatan%2Fdocker-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnatan%2Fdocker-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnatan%2Fdocker-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devnatan","download_url":"https://codeload.github.com/devnatan/docker-kotlin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnatan%2Fdocker-kotlin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28971969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T06:46:42.625Z","status":"ssl_error","status_checked_at":"2026-02-01T06:44:56.173Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","client","docker","docker-kotlin","engine","java","jvm","kotlin","multiplatform"],"created_at":"2024-10-02T17:15:07.129Z","updated_at":"2026-02-15T04:03:11.158Z","avatar_url":"https://github.com/devnatan.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# docker-kotlin\n\ndocker-kotlin allows you to interact with the Docker Engine Remote API.\n\n```kotlin\ndependencies {\n    implementation(\"me.devnatan:docker-kotlin:0.14.4\")\n}\n```\n\n\u003e [!NOTE]\n\u003e Docker Kotlin **currently supports JVM runtime only**. Native platform support (Linux, macOS, Windows, etc.) is under active development in [#209](https://github.com/devnatan/docker-kotlin/pull/209). \n\u003e \n\u003e If you attempt to use Docker Kotlin on native targets before this work is complete, you'll encounter `NotImplementedError`. We're working hard to bring full multiplatform support soon!\n\n## Basic Usage\n\nUse `DockerKotlin { ... }` to create a new Docker client instance with the default settings. Default settings are based on the\ncurrent platform or environment variables, e.g.: socket path will be set to [`DOCKER_HOST`](https://docs.docker.com/compose/environment-variables/envvars/#docker_host)\nif present otherwise `unix://var/run/docker.sock` if the current platform is Unix-like.\n\n```kotlin\nval client = DockerClient {\n    // this: DockerClientConfigBuilder\n}\n```\n\n## Resources\n\n* [System](#system)\n* [Containers](#containers)\n* [Networks](#networks)\n* [Exec](#exec)\n\n### System\n\n#### Get Docker Version\n\n```kotlin\nval version: SystemVersion = client.system.version()\n```\n\n### Containers\n\n#### Create and start a Container with explicit port bindings\n\n```kotlin\nval containerId = client.containers.create(\"busybox:latest\") {\n    // Only if your container doesn't already expose this port\n    exposedPort(80u)\n\n    hostConfig {\n        portBindings(80u) {\n            add(PortBinding(\"0.0.0.0\", 8080u))\n        }\n    }\n}\n\nclient.containers.start(containerId)\n```\n\n#### Create and start a Container with auto-assigned port bindings\n\n```kotlin\nval createdContainerId = client.containers.create(\"busybox:latest\") {\n    // Only if your container doesn't already expose this port\n    exposedPort(80u)\n    \n    hostConfig {\n        portBindings(80u)\n    }\n}\n\nclient.containers.start(createdContainerId)\n\n// Inspect the container to retrieve the auto-assigned ports\nval container = testClient.containers.inspect(createdContainerId)\nval ports = container.networkSettings.ports\n```\n\n#### List All Containers\n\n```kotlin\nval containers: List\u003cContainer\u003e = client.containers.list()\n```\n\n#### Logs\n\n##### Get logs from a container\n```kotlin\nval result = client.containers.logs(containerId) {\n    stdout = true\n    stderr = true\n} as ContainerLogsResult.Complete\n\nprintln(result.output)\n```\n\n##### Stream logs in real-time\n```kotlin\nval result = client.containers.logs(containerId) {\n    stdout = true\n    stderr = true\n    follow = true\n} as ContainerLogsResult.Stream\n\nresult.output.collect { frame -\u003e\n    println(frame.value)\n}\n```\n\n##### Get logs with separated stdout/stderr\n```kotlin\nval result = client.containers.logs(containerId, demux = true) {\n    stdout = true\n    stderr = true\n} as ContainerLogsResult.CompleteDemuxed\n\nprintln(\"STDOUT: ${result.stdout}\")\nprintln(\"STDERR: ${result.stderr}\")\n```\n\n##### Get last N lines of logs\n```kotlin\nval result = client.containers.logs(containerId) {\n    stdout = true\n    tail = \"100\"\n}\n```\n\n##### Get logs with timestamps\n```kotlin\nval result = client.containers.logs(containerId) {\n    stdout = true\n    timestamps = true\n}\n```\n\n##### Get logs since a specific time\n```kotlin\nval result = client.containers.logs(containerId) {\n    stdout = true\n    since = \"10m\"      // last 10 minutes\n    // or: since = \"1609459200\"  // Unix timestamp\n}\n```\n\n#### Stream logs using convenience method\n```kotlin\nclient.containers.logsAsFlow(containerId) {\n    stdout = true\n    stderr = true\n    follow = true\n}.collect { frame -\u003e\n    val prefix = if (frame.stream == Stream.StdErr) \"[ERR]\" else \"[OUT]\"\n    print(\"$prefix ${frame.value}\")\n}\n```\n\n### Networks\n\n#### Create a new Network\n\n```kotlin\nval networkId: String = client.networks.create {\n    name = \"octopus-net\"\n    driver = \"overlay\"\n}\n```\n\n#### List all Networks\n```kotlin\nval networks = client.networks.list()\n```\n\n#### Connect a container to a network\n```kotlin\nclient.networks.connect(networkId, containerId)\n```\n\n### Exec\n\n#### Execute a command in a running container\n```kotlin\nval execId = client.exec.create(containerId) {\n    command = listOf(\"echo\", \"Hello, Docker!\")\n    attachStdout = true\n}\n\nwhen (\n    val result = client.exec.start(execId, ExecStartOptions())\n) {\n    is ExecStartResult.Complete -\u003e println(result.output)\n    else -\u003e error(\"Unexpected result\")\n}\n```\n\n#### Execute a command with streaming output\n```kotlin\nval execId = client.exec.create(containerId) {\n    command = listOf(\"sh\", \"-c\", \"for i in 1 2 3; do echo line \\$i; sleep 1; done\")\n    attachStdout = true\n}\n\nval result = client.exec.start(execId) { stream = true }\nwhen (result) {\n    is ExecStartResult.Stream -\u003e {\n        result.output.collect { chunk -\u003e\n            print(chunk)\n        }\n    }\n    else -\u003e error(\"Unexpected result\")\n}\n```\n\n#### Execute a command with separated stdout/stderr\n```kotlin\nval execId = client.exec.create(containerId) {\n    command = listOf(\"sh\", \"-c\", \"echo stdout; echo stderr \u003e\u00262\")\n    attachStdout = true\n    attachStderr = true\n}\n\nwhen (\n    val result = client.exec.start(execId) { demux = true }\n) {\n    is ExecStartResult.CompleteDemuxed -\u003e {\n        println(\"STDOUT: ${result.output.stdout}\")\n        println(\"STDERR: ${result.output.stderr}\")\n    }\n    else -\u003e error(\"Unexpected result\")\n}\n```\n\n#### Check exec exit code\n```kotlin\nval execId = client.exec.create(containerId) {\n    command = listOf(\"false\")\n}\n\nclient.exec.start(execId) { detach = true }\n\nval execInfo = client.exec.inspect(execId)\nprintln(\"Exit code: ${execInfo.exitCode}\") // Exit code: 1\n```\n\n### File Operations\n\n#### Copy a file from container to host\n```kotlin\nclient.containers.copyFileFrom(\n    container = containerId,\n    sourcePath = \"/var/log/app.log\",\n    destinationPath = \"/tmp/app.log\"\n)\n```\n\n##### Copy a file from host to container\n```kotlin\nclient.containers.copyFileTo(\n    container = \"bailarina-caputina\",\n    sourcePath = \"/home/user/config.json\",\n    destinationPath = \"/app/config/\"\n)\n```\n\n#### Copy a directory from container to host\n```kotlin\nclient.containers.copyDirectoryFrom(\n    container = \"knoten\",\n    sourcePath = \"/app/logs\",\n    destinationPath = \"/tmp/container-logs\"\n)\n```\n\n#### Copy a directory from host to container\n```kotlin\nclient.containers.copyDirectoryTo(\n    container = \"globson\",\n    sourcePath = \"/home/user/configs\",\n    destinationPath = \"/app/\"\n)\n```\n\n#### Advanced copy with custom options\n```kotlin\nclient.containers.copyTo(\n    container = \"tapioca\",\n    destinationPath = \"/app/data\",\n    tarArchive = myTarArchive\n) {\n    path = \"/app/data\"\n    noOverwriteDirNonDir = true  // Don't overwrite if types mismatch\n    copyUIDGID = true            // Preserve UID/GID\n}\n\n// Get raw tar archive from container\nval result = client.containers.copyFrom(containerId, \"/app/config\")\nval tarData = result.archiveData\n\n// Archive info including file metadata\nval stats = result.stat \n```\n\n## License\n\ndocker-kotlin is licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevnatan%2Fdocker-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevnatan%2Fdocker-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevnatan%2Fdocker-kotlin/lists"}