How to enable docker remote api rest in mac OS X with boot2docker?

霸气de小男生 提交于 2020-01-06 03:34:27

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/31264333/how-to-enable-docker-remote-api-rest-in-mac-os-x-with-boot2docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!