Reputation: 1
Right now I'm working on a small GUI for using docker. I'm using electron.js and Vue.js for this. Since desktop applications written in electron are embedded Chrome apps, I have a problem when I try to send request to docker REST API:
XMLHttpRequest cannot load http://localhost:2375/containers/json.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:9080' is therefore not allowed access
Nothing unusual, its behaving like it should since its a browser.
The real question is how to enable CROSS request to docker REST API ?
I'm using version 17.03.0-ce
Upvotes: 0
Views: 1800
Reputation: 176
The docker daemon provides options to enable CORS headers for the REST API.
When starting the daemon, try setting the flags --api-enable-cors
and --api-cors-header
, for instance:
sudo dockerd --api-enable-cors --api-cors-header=http://localhost:9080
The REST API should then provide the necessary headers. Interestingly, --api-enable-cors
is not documented in the docs, but nonetheless required.
Upvotes: 1