docker打开remote接口设置

前言

 本文记录docker怎么打开api remote接口设置,docker的版本更新太快了,不同的版本之间,设置可能不同,本文是针对docker13.1

1、 查看配置文件位于哪里

systemctl show --property=FragmentPath docker 


2、编辑配置文件内容,接收所有ip请求

vim  /lib/systemd/system/docker.service 
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:5678

或者 

sudo systemctl edit docker.service

 to open an override file for docker.service

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375

或者

Configuring remote access with daemon.json

Set the hosts array in the /etc/docker/daemon.json to connect to the UNIX socket and an IP address, as follows:

{
"hosts": ["unix:///var/run/docker.sock", "tcp://127.0.0.1:2375"]
}

 check status

sudo netstat -lntp | grep dockerd
tcp        0      0 127.0.0.1:2375          0.0.0.0:*               LISTEN      3758/dockerd

3、重新加载配置文件,重启docker daemon

sudo systemctl daemon-reload 
sudo systemctl restart docker

4、测试

[root@node1 docker]# docker -H localhost:5678 version
Client:
 Version:      1.13.1
 API version:  1.26
 Go version:   go1.7.5
 Git commit:   092cba3
 Built:        Wed Feb  8 06:38:28 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.13.1
 API version:  1.26 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   092cba3
 Built:        Wed Feb  8 06:38:28 2017
 OS/Arch:      linux/amd64
 Experimental: false
[root@node1 docker]# curl -v -X GET localhost:5678/_ping
* About to connect() to localhost port 5678 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 5678 (#0)
> GET /_ping HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:5678
> Accept: */*
> 
< HTTP/1.1 200 OK
< Api-Version: 1.26
< Docker-Experimental: false
< Server: Docker/1.13.1 (linux)
< Date: Wed, 29 Nov 2017 08:58:12 GMT
< Content-Length: 2
< Content-Type: text/plain; charset=utf-8
< 
* Connection #0 to host localhost left intact
OK[root@node1 docker]# systemctl show --property=FragmentPath docker 
FragmentPath=/usr/lib/systemd/system/docker.service

表示docker remote api打开成功

参考:https://docs.docker.com/install/linux/linux-postinstall/

posted @ 2019-05-15 11:00  柚子=_=  阅读(563)  评论(0编辑  收藏  举报