主要是在[Service]这个部分,加上下面两个参数:
-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
# vim /usr/lib/systemd/system/docker.service
[Service]
ExecStart=/usr/bin/docker -d -H unix://var/run/docker.sock -H tcp://0.0.0.0:2375
# systemctl daemon-reload
# systemctl restart docker
# ps -ef|grep docker
root 26208 1 0 23:51 ? 00:00:00 /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 886/sshd
tcp6 0 0 [::]:2375 [::]:* LISTEN 26208/dockerd
$ sudo docker -H tcp://10.141.211.176:2375 images
REPOSITORY TAG IMAGE ID CREATED SIZE
* 要在别的服务器上远程访问,才能得到,本机不行,可能是配了代理的原因
sudo docker -H tcp://10.141.211.176:2375/images/json | python -mjson.tool
curl http://10.141.211.176:2375/containers/json |python -m json.tool
sudo curl -X POST -H "Content-Type: application/json" -d '{
"Hostname": "",
"User": "",
"MemorySwap": 0,
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Image": "test/test-ui-dashboard",
"Tag": "latest",
"WorkingDir": "",
"ExposedPorts": {"8082/tcp": { }},
"NetworkDisabled": false,
"HostConfig": {
"PortBindings": {
"8082/tcp": [ {"HostPort": "8082"} ]
}
}
}' http://10.141.211.176:2375/containers/create?name=myapiserver
curl http://10.141.211.176:2375/containers/0c51c77395dccc4af3d899c5046d876ac1eb235d025d103864165ed4290ab81d/json |python -m json.tool
curl http://10.141.211.176:2375/containers/282cc100968b2d1df735116346d3bc52a14e9518e7e1de70dc27c78e35f9ed38/logs |python -m json.tool
curl -v -X POST -H -d http://10.141.211.176:2375/containers/0d581b39e7edd426d765a0c4297c985832f751a61510621ff75046c45ff8ca42/start
curl http://10.141.211.176:2375/networks
sudo curl -X POST -H "Content-Type: application/json" -d '
{
"Container": "751eae59e0ae"
}'http://10.141.211.176:2375/network/6da120a74ece9e656e4d36e0fb91751c7a3a331fcf0cc257577b9340c0ce6034/connect