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

 傻要傻到嗨样 发布于 2022-10-25 09:25

新版本的docker for Mac去除了docker-machine指令
我现在怎么获取 rest api 开发的端口呢?
比如:
curl -XGET http://localhost:2376/images/... | python -mjson.tool

可是,貌似不是上面的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
    2022-10-26 14:45 回答
  • 这里的端口取决于你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

    2022-10-26 14:45 回答
  • 默认使用的/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

    可以正常执行

    2022-10-26 14:45 回答
  • 我这里通过一种折中的办法
    环境: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

    2022-10-26 14:45 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有