问题
I used this official guide to install Docker Containers on Windows. Everything looks good and I can run IIS on Windows Containers now.
However, I don't see it anywhere and have no idea on how to "Enable Rest API" for it. How can I do this?
回答1:
(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!
回答2:
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
.
- Check docker version
- Check the URL of the machine I want to connect to (
default
>192.168.99.100:2376
) - Set an Environment Variable to the location of the certificates
- 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...
- Docker REST API - https://docs.docker.com/engine/api/v1.24/
来源:https://stackoverflow.com/questions/37854161/how-do-i-enable-the-docker-restapi-on-windows-containers