2013-10-18 20 views
1

我有Docker在/var/run/docker.sock上運行。使用unix套接字的docker websocket附件

我想附加到一個容器。所以我砍了ws庫讓它在它的請求中發送socketPath和路徑。基本上,它看到ws+unix:///var/run/docker.sock:/containers/theid/attach/ws?args並做正確的事情。問題是:docker在請求中返回403禁止。 websocket是否通過剛剛禁用的unix套接字訪問? 如果我向http://localhost:3000/containers/theid/attach/ws?args發出同樣的請求,websocket連接可以正常工作(我有docker守護程序在http和unix套接字上偵聽)。

此外,望着泊塢窗守護程序日誌,我看到預期的GET請求

謝謝!

+0

由於您沒有鏈接到您的代碼,你也給正在運行的泊塢窗守護進程的輸出調試'docker -d -D' API設置在'api.go'中完成 https://github.com/dotcloud/docker/blob/master/api.go#L1013 https:// github。 com/dotcloud/docker/blob/master/api.go#L778 – 2013-10-20 13:07:14

+0

好吧我會這麼做 –

+0

@JaredForsyth hi jared,你能分享你的tcp套接字連接嗎?我有正常的tcp套接字403禁止請求錯誤http://stackoverflow.com/questions/23119145/docker-websocket-attaching-in-nodejs?stw=2 – Mustafa

回答

0

的內部使用的WebSocket庫目前驗證請求以包含Origin頭與一個有效的URL:

func checkOrigin(config *Config, req *http.Request) (err error) { 
    config.Origin, err = Origin(config, req) 
    if err == nil && config.Origin == nil { 
     return fmt.Errorf("null origin") 
    } 
    return err 
} 

(從片段:https://github.com/golang/net/blob/master/websocket/server.go#L102)。

如果標頭無效或丟失,您將得到狀態403響應,儘管Docker日誌不顯示任何錯誤。

一個簡單的解決方案是一個有效的頭添加到您的初始請求看起來像這樣:

Origin: http://localhost