您的位置:首页技术文章
文章详情页

docker api 开发的端口怎么获取?

【字号: 日期:2024-10-19 15:33:10浏览:9作者:猪猪

问题描述

新版本的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/jsondocker api 开发的端口怎么获取?

回答2:

默认使用的/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

相关文章: