docker

0.1.1

Docker client API's

Carter Mbotho<lastcarter@gmail.com> MIT 0 downloads Repository

docker

A native Cxy client library for interacting with the Docker Engine API.

Designed as an application-unaware, general-purpose library for any Cxy project that needs container lifecycle management, command execution, and distributed Docker Swarm cluster orchestration.

Features

  • Native Cxy Implementation Zero CLI binary dependencies, built directly on stdlib/fetch.cxy.
  • Fast Track to Execution Connect, pull images, create containers, stream logs, and exec commands.
  • Full Docker Swarm Mode Cluster init/join/leave, node management, replicated/global services, task tracking, secrets, and configs.
  • Multiplexed I/O Demuxer Native binary parsing of Docker's 8-byte frame header separating stdout and stderr directly into OutputStream.
  • Archive Transfer High-performance filesystem tar streaming via BinaryOutputStream and req.setBytes.
  • Storage & Networking Persistent named volumes, host directory bind mounts, custom networks, and port mappings.
  • Observability Real-time system events stream (GET /events) and container resource stats (CPU, RAM, Network).
  • System Maintenance Reclaim disk space via container, image, volume, and network prune endpoints.
  • mTLS Security Encrypted TCP connections with mutual TLS authentication using DOCKER_TLS_VERIFY, DOCKER_CERT_PATH, and SslContext.

Quick Start

import { DockerClient, ContainerConfig, Vector } from "@docker"

func main() {
    var client = DockerClient.fromEnv()

    if (!client.ping()) {
        eprintln("Cannot connect to Docker daemon")
        return
    }

    // 1. Pull image
    client.images().pull("alpine:latest")

    // 2. Create and run a container
    var cmd = Vector[String]()
    cmd.push(String("echo"))
    cmd.push(String("Hello from Docker!"))

    var container = client.containers().create(ContainerConfig{
        image: String("alpine:latest"),
        cmd: &&cmd
    })

    client.containers().start(container.id.s())
    client.containers().wait(container.id.s())

    // 3. Retrieve logs
    var logs = client.containers().logs(container.id.s())
    print(logs)

    // 4. Cleanup
    client.containers().remove(container.id.s(), true)
}

Docker Swarm Mode

import { DockerClient, SwarmInitConfig, ServiceSpec, TaskTemplate, ContainerSpec } from "@docker"

func main() {
    var client = DockerClient()

    // Initialize Swarm cluster
    var info = client.swarm().initialize(SwarmInitConfig{
        listenAddr: String("0.0.0.0:2377")
    })
    println(f"Swarm initialized! Worker token: {info.joinTokens.worker}")

    // Deploy a replicated service
    var res = client.services().create(ServiceSpec{
        name: String("web"),
        taskTemplate: TaskTemplate{
            containerSpec: ContainerSpec{
                image: String("nginx:alpine")
            }
        }
    })

    // Scale service to 3 replicas
    client.services().scale(res.id.s(), 3)

    // Teardown
    client.services().remove(res.id.s())
    client.swarm().leave(true)
}

Testing

cxy package test

License

MIT

Install
cxy package add docker
Versions
0.1.12026-11-16T06:21:15Z
0.1.0yanked2026-11-16T06:19:24Z