How do I enable the Docker RestAPI on Windows Containers?

情到浓时终转凉″ 提交于 2019-12-06 05:59:52

(Posted on behalf of the OP).

Finally, I found how to enable Remote API of Docker Containers on Windows. The key point is file daemon.json which place in C:\ProgramData\docker\config.

In the guide linked in the question, the author only mention that we should place in it something like:

{"hosts": ["tcp://0.0.0.0:2376", "npipe://"]}  

But when I try to add this to daemon.json, my daemon don't work on CLI. At last, I reverse the order of array like

{"hosts": ["npipe://", "tcp://0.0.0.0:2376"]}   

My docker will work well in both CLI & Remote API. Good experience with Windows Docker and thanks for your attention!

Just came across the same issue, and discovered the REST API was already enabled!

TLDR;

set API=https://192.168.99.100:2376/v1.24/containers/json?all=1
set CERT=C:\Users\Nick\.docker\machine\machines\default
curl --cert "%CERT%/cert.pem" --cacert "%CERT%/ca.pem" --key "%CERT%/key.pem" "%API%"

Here's how I accessed the REST API from the windows cmd.

  1. Check docker version
  2. Check the URL of the machine I want to connect to (default > 192.168.99.100:2376)
  3. Set an Environment Variable to the location of the certificates
  4. Perform a CURL request on the REST endpoint (/v1.24/containers/json?all=1)

i.e.

C:\Users\Nick>docker --version
Docker version 18.03.0-ce, build 0520e24302

C:\Users\Nick>docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
default   -        virtualbox   Running   tcp://192.168.99.100:2376           v18.03.0-ce

C:\Users\Nick>set DOCKER_CA=C:\Users\Nick\.docker\machine\machines\default

C:\Users\Nick>curl --cert "%DOCKER_CA%/cert.pem" --cacert "%DOCKER_CA%/ca.pem" --key "%DOCKER_CA%/key.pem" https://192.168.99.100:2376/v1.24/containers/json?all=1
[]

For those that are interested...

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