             host (urly/url-like (str "http://" (.host cli)))
             domain (str (name app-name) "." (config/domain-name))]
         (router/add-domain domain)
-        (router/add-upstream domain (str "http://" (urly/host-of host) ":" port))
+        (router/add-upstream domain (str "http://" (urly/host-of host) ":" host-port))
         (swap! apps assoc app-name {:image image
                                     :tag tag
                                     :user-id (:id user)

(defn create [app-name user image & {:keys [tag command port]}]
  (let [app-name (keyword app-name)
        cli (choose-client)
        port-bindings [(port-binding (generate-host-port (.host cli))
                                     port)]]
    (if (nil? (app-name @apps))
      (let [id (docker/run cli image :tag tag
                                     :cmd command

  (docker/make-client "127.0.0.1:4243"))

(defn generate-host-port [host]
  (+ 10000 (rand-int 1000)))

(defn port-binding [host-port container-port]
  {(str container-port "/tcp") [{"HostPort" (str host-port)}]})

(defn app->id [app-name user]
  (get-in @apps [(keyword app-name) :instances 0 :id]))
