pod-lispyclouds-docker
pod-lispyclouds-docker copied to clipboard
A babashka pod for interacting with docker
pod-lispyclouds-docker
A babashka pod for interacting with docker. Uses the clj-docker-client to function.
DEPRECATION NOTICE: contajners is recommended to use instead of this pod. It is source compatible with babashka and supports much more features and has less limitations as compared to the this pod. Also more engines like podman are supported. This codebase won't receive any further updates.
Building prerequisites
- Graal VM
- Clojure CLI(faster) or Leiningen(better windows support)
Building
Installing GraalVM:
- Download and extract GraalVM CE. Go to the extracted location and navigate to the directory where you can find bin, lib, jre and other directories.
- Run
export GRAALVM_HOME=$PWD.
Clone the repo and from the repo directory:
- Run
$GRAALVM_HOME/bin/gu install native-imageto get the Graal native compiler. - Run
clojure -A:native-imageif using Clojure CLI orlein native-imagewith leiningen to compile it to a native executable. - The executable is found in
target/if compiled via Clojure CLI or intarget/default+uberjar/with leiningen.
Usage
- Fire up a babashka v0.0.92+ REPL with
rlwrap bb - Import pods:
(require '[babashka.pods :as pods]) - Load this pod:
(pods/load-pod ["pod-lispyclouds-docker"]). Assumes pod-lispyclouds-docker is on the PATH. - Load the ns:
(require '[pod.lispyclouds.docker :as docker]) - See the Usage section to try out the commands.
- Calling invoke with
:as streamand:as :socketare unsupported at the moment.
Sample script to pull an image, create a container and fetch its logs
(require '[babashka.pods :as pods])
;; Assumes pod-lispyclouds-docker is on the PATH.
(pods/load-pod ["pod-lispyclouds-docker"])
(require '[pod.lispyclouds.docker :as docker])
(def images (docker/client {:category :images
:conn {:uri "unix:///var/run/docker.sock"}}))
(def containers (docker/client {:category :containers
:conn {:uri "unix:///var/run/docker.sock"}}))
;; pull the "busybox:musl" image
(docker/invoke images {:op :ImageCreate
:params {:fromImage "busybox:musl"}})
;; create a container called "conny" from it
(docker/invoke containers {:op :ContainerCreate
:params {:name "conny"
:body {:Image "busybox:musl"
:Cmd ["echo" "hello"]}}})
(docker/invoke containers {:op :ContainerStart
:params {:id "conny"}})
(def logs (docker/invoke containers {:op :ContainerLogs
:params {:id "conny"
:stdout true}}))
(println logs)