如何启用docker远程api休息在Mac OS X与boot2docker? [英] How to enable docker remote api rest in mac OS X with boot2docker?

查看:324
本文介绍了如何启用docker远程api休息在Mac OS X与boot2docker?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是码头工人的新人。我想使用docker远程api,但是我失败了。首先,我使用的是远程API客户端库的 docker-java 。它抛出异常是:

 服务器无法响应有效的HTTP响应

更多详细信息是这里。所以我想知道这是什么问题。我使用远程休息api连接我的docker从这个教程。但它还没有工作。我使用命令:

  curl -v http://192.168.59.103:2376/info 

并向我显示此信息:

  * DNS缓存中未找到主机名
*尝试192.168.59.103 ...
*连接到192.168.59.103(192.168.59.103)端口2376(#0)
> GET / info HTTP / 1.1
>用户代理:curl / 7.37.1
>主持人:192.168.59.103:2376
>接受:* / *
>

*连接#0到主机192.168.59.103保持原状

我想它可以连接到这个ip,但不是有效的响应。谁能明白这是什么意思?然后我在google中找到问题。有人说,需要添加ip:2376到virtualBox。我已经做了。但是,它仍然没有奏效。我只想使用rest api来请求我的docker。当我使用这个命令:

  curl -v http://192.168.59.103:2376/info 

我希望它可以显示我正常的信息。有人告诉我,我需要没有TLS。但是,我不知道该怎么做。请教我一步一步。我真的很接近码头。谢谢。我使用Mac OS X.而Docker Api是1.19,客户端版本是1.7.0。

解决方案

你正在尝试访问docker在https端口是2376,如果你想使用没有https的curl,你将不得不打到正常http的2375端口,但默认情况下它被禁用。



但是您可以首先运行

  boot2docker ssh 

然后逐个运行这些命令

  cp / etc / init.d / docker〜/ docker.bak 
sudo sed -i的/ DOCKER_TLS:= auto / DOCKER_TLS:= no / 1'/etc/init.d/docker
sudo / etc /init.d/docker stop
sudo /etc/init.d/docker start

这将禁用https,现在您可以执行

  curl -v http://192.168.59.103:2375/info 

注意不同的端口!



你还要使用你正常的 docker 命令,所以进入你的 .bashrc 并更改此网址:

  export DOCKER_HOST = tcp:// 192.168.59.103:2376 
export DOCKER_CERT_PATH = / Users / kevinsimper / .boot2docker / certs / boot2docker-vm
export DOCKER_TLS_VERIFY = 1

  export DOCKER_HOST = tcp://192.168.59.103:2375 
export DOCKER_CERT_PATH = / Users / kevinsimper / .boot2docker / certs / boot2docker-vm
export DOCKER_TLS_VERIFY = 0


I'm new to docker. I want to use docker remote api, But I failed. Firstly, I use the docker-java that is Remote API client libraries. It throws Exception is:

The server failed to respond with a valid HTTP response

more detail is here.So, I want to know what is wrong about it. I use the remote rest api to connect my docker from this tutorial. But it didn't work yet. I use the command:

curl -v http://192.168.59.103:2376/info

and show me this information:

* Hostname was NOT found in DNS cache
*   Trying 192.168.59.103...
* Connected to 192.168.59.103 (192.168.59.103) port 2376 (#0)
> GET /info HTTP/1.1
> User-Agent: curl/7.37.1
> Host: 192.168.59.103:2376
> Accept: */*
> 

* Connection #0 to host 192.168.59.103 left intact

I think it can connect to this ip, But not valid response. Who can understand what this means? Then I find the question in google. Some people said that it need to add ip:2376 to virtualBox. I have done it. But, it still didn't work. I just want to use rest api to request my docker. When I use this command :

curl -v http://192.168.59.103:2376/info

I hope it can show me normal information. Someone told me I need make it without TLS. But, I don't know how to do. Please teach me step by step. I'm really new to docker. Thanks. I use Mac OS X. And docker Api is 1.19, and client version is 1.7.0.

解决方案

You are trying to access docker on the https port which is 2376, if you want to use curl without https, you would have to hit the 2375 port which is normal http, but by default it is disabled.

But you can enabled it by first running

boot2docker ssh

and then running these commands one by one

cp /etc/init.d/docker ~/docker.bak
sudo sed -i 's/DOCKER_TLS:=auto/DOCKER_TLS:=no/1' /etc/init.d/docker
sudo /etc/init.d/docker stop
sudo /etc/init.d/docker start

This disables https and now you can do

curl -v http://192.168.59.103:2375/info

Notice the different port!

You still want to use your normal docker command, so go into your .bashrc and change this url:

export DOCKER_HOST=tcp://192.168.59.103:2376
export DOCKER_CERT_PATH=/Users/kevinsimper/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1

to

export DOCKER_HOST=tcp://192.168.59.103:2375
export DOCKER_CERT_PATH=/Users/kevinsimper/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=0

这篇关于如何启用docker远程api休息在Mac OS X与boot2docker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆