Home  >  Q&A  >  body text

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

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

可是,貌似不是上面的2376端口。
谢谢指教。

天蓬老师天蓬老师2757 days ago829

reply all(4)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-25 09:04:30

    I adopt a compromise method here
    Environment: MacOS
    Type in the shell: vim ~/.bash_profile, type the following code at the end of the file

    alias dest='rest_fun(){ curl --unix-socket /var/run/docker.sock http: | python -mjson.tool ;};rest_fun '
    

    Save and exit, restart the shell.
    Then you can use the dest command to implement some functions, such as listing images:
    dest /images/json

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-04-25 09:04:30

    /var/run/docker.sock is used by default for communication. You can use the -H parameter to specify the corresponding listening port.
    If you are using the default socket communication mode, you can use curl’s unix-socket method for testing.

    curl --unix-socket /var/run/docker.sock http:/v1.24/info

    The above instructions are in

    Server:
     Version:      1.12.1
     API version:  1.24

    Can be executed normally

    reply
    0
  • 为情所困

    为情所困2017-04-25 09:04:30

    The port here depends on the port bound to your docker daemon.

    If no port is specified when the daemon is running, it will be used by defaultunix:///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...

    For example when running:

    docker -d -H unix:///var/run/docker.sock -H 0.0.0.0:2376

    It is equivalent to binding the default socket to 2376 of the local machine, which is what you saidhttp://localhost:2376

    reply
    0
  • 世界只因有你

    世界只因有你2017-04-25 09:04:30

    If you don’t want to change the configuration file, just use the mirror to proxy. Pay attention to mounting/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

    reply
    0
  • Cancelreply