docker api 開發的端口怎么獲取?
問題描述
新版本的docker for Mac去除了docker-machine指令我現在怎么獲取 rest api 開發的端口呢?比如:curl -XGET http://localhost:2376/images/... | python -mjson.tool
可是,貌似不是上面的2376端口。謝謝指教。
問題解答
回答1:我這里通過一種折中的辦法環境:MacOS在shell里敲入:vim ~/.bash_profile ,在文件的末尾鍵入下面代碼
alias dest=’rest_fun(){ curl --unix-socket /var/run/docker.sock http:$1 | python -mjson.tool ;};rest_fun $1’
保存退出,重啟shell。然后就可以使用dest指令實現一些功能,如羅列images:dest /images/json
默認使用的/var/run/docker.sock進行通信, 可以使用-H參數指定相應的監聽端口如果使用的是默認的socket通信模式的話 可以使用curl的unix-socket方式進行測試
curl --unix-socket /var/run/docker.sock http:/v1.24/info
上述的指令在
Server: Version: 1.12.1 API version: 1.24
可以正常執行
回答3:這里的端口取決于你docker daemon綁定的端口。
如果daemon運行時沒有指定端口,默認用unix:///var/run/docker.sock
By default the Docker daemon listens on unix:///var/run/docker.sock and the client must have root access to interact with the daemon. If a group named docker exists on your system, docker applies ownership of the socket to the group.https://docs.docker.com/engin...
例如運行時:
docker -d -H unix:///var/run/docker.sock -H 0.0.0.0:2376
相當于將默認的socket綁定在本機的2376,也就是你說的http://localhost:2376
回答4:不想改配置文件的話, 直接使用鏡像來代理就好了。 注意掛載/var/run/docker.sock
docker run -d -ti -p 2375:2375 -v /var/run/docker.sock:/var/run/docker.sock ehazlett/docker-proxy:latest -i
相關文章:
