docker api 開(kāi)發(fā)的端口怎么獲取?
問(wèn)題描述
新版本的docker for Mac去除了docker-machine指令我現(xiàn)在怎么獲取 rest api 開(kāi)發(fā)的端口呢?比如:curl -XGET http://localhost:2376/images/... | python -mjson.tool
可是,貌似不是上面的2376端口。謝謝指教。
問(wèn)題解答
回答1:我這里通過(guò)一種折中的辦法環(huán)境: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指令實(shí)現(xiàn)一些功能,如羅列images:dest /images/json
默認(rèn)使用的/var/run/docker.sock進(jìn)行通信, 可以使用-H參數(shù)指定相應(yīng)的監(jiān)聽(tīng)端口如果使用的是默認(rèn)的socket通信模式的話 可以使用curl的unix-socket方式進(jìn)行測(cè)試
curl --unix-socket /var/run/docker.sock http:/v1.24/info
上述的指令在
Server: Version: 1.12.1 API version: 1.24
可以正常執(zhí)行
回答3:這里的端口取決于你docker daemon綁定的端口。
如果daemon運(yùn)行時(shí)沒(méi)有指定端口,默認(rèn)用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...
例如運(yùn)行時(shí):
docker -d -H unix:///var/run/docker.sock -H 0.0.0.0:2376
相當(dāng)于將默認(rèn)的socket綁定在本機(jī)的2376,也就是你說(shuō)的http://localhost:2376
回答4:不想改配置文件的話, 直接使用鏡像來(lái)代理就好了。 注意掛載/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
相關(guān)文章:
1. Java后端需要掌握angular.js嗎?是主要在后臺(tái)的前臺(tái)用嗎?2. 【python小白】 問(wèn)關(guān)于導(dǎo)入嵌套的包的問(wèn)題3. nginx和web服務(wù)都跑在docker容器里時(shí),nginx負(fù)載均衡如何配置服務(wù)的IP地址4. html5 - 使用canvas的fillText方法寫(xiě)文字時(shí),坐標(biāo)的問(wèn)題。5. Java 中的synchronized鎖代碼塊的時(shí)候需不需要這個(gè)類(lèi)是單例6. angular.js - angular2 有什么cool的loading組件么?7. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問(wèn)8. 一個(gè)阿里云的服務(wù)器,可以部署兩個(gè)javaweb項(xiàng)目嗎??jī)蓚€(gè)項(xiàng)目域名不同9. javascript - vue2.0動(dòng)態(tài)加載多個(gè)相同組件,給組件中的data輸入不同的值,關(guān)閉非最后一個(gè)組件時(shí),銷(xiāo)毀的值是最后一個(gè)組件值。10. javascript - 如何判斷一個(gè)點(diǎn)是否在svg一個(gè)閉合的路徑中?
