(ns replme.components.docker
  (:require [com.stuartsierra.component :as component]
            [docker.core :as docker]
            [clojure.tools.logging :as log]))

(defrecord Docker [url client]
  component/Lifecycle
  (start [component]
    (if (:client component) 
      component
      (do (log/info (str "Connecting to docker server at " url))
          (assoc component :client (docker/make-client url)))))

  (stop [component]
    (if-not (:client component)
      component
      (do (log/info "Disconnected from Docker")
          (dissoc component :client)))))

(defn new-docker
  [url]
  (map->Docker {:url url}))

(ns replme.components.docker
  (:require [com.stuartsierra.component :as component]
            [docker.core :as docker]
            [docker.container :as container]
            [clojure.tools.logging :as log]))

(defrecord Docker [url client]
  component/Lifecycle
  (start [component]
    (if (:client component) 
      component
      (do (log/info (str "Connecting to docker server at " url))
          (let [client (docker/make-client url)]
            (doseq [old-container (map :Id (container/show-all client))]
              (container/remove client old-container :force true))
            (assoc component :client client)))))

  (stop [component]
    (if-not (:client component)
      component
      (do (log/info "Disconnected from Docker")
          (dissoc component :client)))))

(defn new-docker
  [url]
  (map->Docker {:url url}))

Remove old containers on startup
Remove old containers on startup

replme/replme,clojurecup2014/replme,replme/replme-frontend,clojurecup2014/replme