Liking cljdoc? Tell your friends :D

clj-docker-client Build Status

License: GPL v3 Clojars Project

An idiomatic Clojure Docker client based on the excellent JVM client by Spotify.

Why not use the Spotify lib directly?

The Spotify lib though being excellent, has Java style vararg method calls, non-standard variable passing and undocumented behaviour. This eases out these things to make an idiomatic, clojure friendly API to Docker.

This is a work in progress and aims to be fully compliant and up to date with the Docker API changes.

Installation

Leiningen/Boot

[lispyclouds/clj-docker-client "0.1.6"]

Clojure CLI/deps.edn

{lispyclouds/clj-docker-client {:mvn/version "0.1.6"}}

Gradle

compile 'lispyclouds:clj-docker-client:0.1.6'

Maven

<dependency>
  <groupId>lispyclouds</groupId>
  <artifactId>clj-docker-client</artifactId>
  <version>0.1.6</version>
</dependency>

Requirements

  • Clojure 1.9+
  • JDK 1.8+

Running tests locally

  • Install leiningen
  • Install Docker
  • lein test to run all unit tests. (needs Docker and working internet)

Usage

(require '[clj-docker-client.core :as docker])

Creating a connection to the local Docker daemon

(def conn (docker/connect))

Closing the connection to the Docker daemon

(docker/disconnect conn)

Ping the Docker server

(docker/ping conn)

Get system-wide Docker info

(docker/info conn)

Build login info with Docker Hub

(def login-info (docker/register conn "username" "password"))

Image Handling

Pulling the busybox:musl image

(docker/pull conn "busybox:musl")

Building an image from a Dockerfile

(docker/build
  conn
  "full path to directory containing a Dockerfile"
  "repo-name"
  "tag")

Pushing an image

(docker/push conn "image id or <repo>:<tag>" login-info)

Removing an image

(docker/image-rm conn "image id or <repo>:<tag>")

Listing all available images

(docker/image-ls conn)

Committing changes from a container to a new image

(docker/commit-container
  conn
  "container id"
  "repo"
  "tag"
  "entry point command")

Container Handling

Creating a container with the busybox:musl image, a command and a env var

(docker/create conn "busybox:musl" "echo hello" {:env "testing"})

Listing all available containers

(docker/ps conn) ; Only running containers
(docker/ps conn true) ; All containers

Starting a container

(docker/start conn "name or id")

Stopping a container

(docker/stop conn "name or id")

Killing a container

(docker/kill conn "name or id")

Restarting a container

(docker/restart conn "name or id")

Pausing a container

(docker/pause conn "name or id")

Un-pausing a container

(docker/un-pause conn "name or id")

Running from an image directly

(docker/run conn "image" "command" {:env "test"}) ; Waits for container exit
(docker/run conn "image" "command" {:env "test"} true) ; Detached, returns immediately

Getting logs from a container

(docker/logs conn "name or id")

Getting the current container state

(docker/container-state conn "name or id")

Removing a container

(docker/rm conn "id or name") ; Remove non-running container
(docker/rm conn "id or name" true) ; Force remove non-running container

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close