docker api 開發(fā)的端口怎么獲取?
問題描述
新版本的docker for Mac去除了docker-machine指令我現(xiàn)在怎么獲取 rest api 開發(fā)的端口呢?比如:curl -XGET http://localhost:2376/images/... | python -mjson.tool
可是,貌似不是上面的2376端口。謝謝指教。
問題解答
回答1:我這里通過一種折中的辦法環(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)聽端口如果使用的是默認(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í)沒有指定端口,默認(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,也就是你說的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
相關(guān)文章:
1. mysql - 記得以前在哪里看過一個(gè)估算時(shí)間的網(wǎng)站2. javascript - 能否讓vue-cli的express修改express重啟服務(wù)3. Span標(biāo)簽4. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題5. golang - 用IDE看docker源碼時(shí)的小問題6. docker start -a dockername 老是卡住,什么情況?7. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?8. docker gitlab 如何git clone?9. docker-compose 為何找不到配置文件?10. 請(qǐng)教各位大佬,瀏覽器點(diǎn) 提交實(shí)例為什么沒有反應(yīng)
