2017-02-28 22 views
2

我目前在管道中使用Docker羣集模式,並且我大量使用docker stack deploy -c compose-file.yml name-of-the-stack作爲使用最新碼頭映像更新堆棧的命令。它完美的工作,除非我不從yaml文件中刪除服務。在這種情況下,stack deploy命令應該在更新另一個服務的圖像時除去不再存在的服務,但行爲是它使容器運行並且這不是預期的行爲。 因爲這個我改變它與docker stack rm name-of-the-service然後docker stack deploy -c compose-file.yml name-of-stack。但是這有另一個可怕的副作用,隨機影響容器:docker stack rm name-of-the-stack命令往往使nginx容器proxypass的可靠性完全不可靠(似乎與此問題相關https://github.com/docker/docker/issues/24244)。 事實上,nginx容器(即在另一個堆棧中,但在同一覆蓋網絡中)負責處理容器之間的所有請求,並使用Docker羣組模式的路由網格功能在它們之間建立代理通道,在部署堆棧的重新創建之後,無法代理請求,就好像它試圖將流量轉發到沒有更多存在的容器一樣,這會導致集成和行爲測試失敗。 有沒有一種方法可以不使用docker stack rm(目前看起來很麻煩)而是應用yml撰寫文件的最新狀態?碼頭堆棧部署不會刪除當前yaml撰寫文件中未聲明的服務

回答

3

您需要在您的docker stack deploy命令--prune選項:

$ docker stack deploy --help 

Usage: docker stack deploy [OPTIONS] STACK 

Deploy a new stack or update an existing stack 

Aliases: 
    deploy, up 

Options: 
     --bundle-file string Path to a Distributed Application Bundle file 
    -c, --compose-file string Path to a Compose file 
     --help     Print usage 
     --prune     Prune services that are no longer referenced 
     --with-registry-auth Send registry authentication details to Swarm agents