clj-docker-client
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.5"]
Clojure CLI/deps.edn
{lispyclouds/clj-docker-client {:mvn/version "0.1.5"}}
Gradle
compile 'lispyclouds:clj-docker-client:0.1.5'
Maven
<dependency>
<groupId>lispyclouds</groupId>
<artifactId>clj-docker-client</artifactId>
<version>0.1.5</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)
Build login info with Docker Hub
(def login-info (docker/register conn "username" "password"))
Image Handling
busybox:musl
image
Pulling the (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)
Container Handling
busybox:musl
image, a command and a env var
Creating a container with the (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")
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