         url (str "http://" (urly/host-of host) ":" port)]
     url))
 
-(defn app->id [app-name user]
-  (get-in @apps [(keyword app-name) :instances 0 :id]))
+(defn instances [app-name]
+  (let [app (wcar* (redis/get (str "apps:" app-name)))]
+    (:instances app)))
 
 (defn create [app-name user image & {:keys [tag command port]}]
   (let [backends (pick-backends)
         front-url (default-frontend-url app-name)
-        old-isntances (get-in @apps [(keyword app-name) :instances])
+        old-isntances (instances app-name)
         new-instances (vec (for [{cli :client host-port :port} backends]
                              (let [id (docker/run cli image
                                         :tag tag

  )

(defn delete [app-name user]
  (let [instances (get-in @apps [(keyword app-name) :instances])]
    (delete-instances instances)
    (swap! apps dissoc (keyword app-name))
    (router/delete-domain (default-frontend-url app-name))
    nil))



(defn logs [app-name user]
  (let [{cli :client} (first (pick-backends))
        resp (container/logs cli (-> app-name instances first :id) :stdout true :stderr true)]
    (map #(str (name (:stream-type %))
               ": "
               (:body %)) resp)))
