I have activated my Docker Engine V1.41 REST API in docker with this artcile: https://blog.usejournal.com/how-to-enable-docker-remote-api-on-docker-host-7b73bd3278c6

After that in my browser it works fine like http://localhost:port/container/list will show me all lists of my containers in json.

But now, when I try to reach the API with axios in react I get an CORS error: enter image description here

So I think I have to setup cors for docker?

I found a bunch of articles about how to enable CORS for a docker image / container but nothing about enabling it for the docker agent / host itself.

Know someone who can answer?

  • Why do your posts all contain a superfluous link to opstrainerz.com? Maybe you should be asking them for help and not S/O if their training is not clear? Is no one at opstrainerz "trained" well enough to answer? Are you misleadingly trying to drive traffic to the site? Do you have an association to the site?
    – Ian W
    Jan 5, 2021 at 4:26

1 Answer 1


CORS is applied at the application layer, not the infrastructure (docker) layer. So, this has nothing to do with docker. It also has nothing to do with the axios client. Rather, your server needs to allow requests from your client by returning the correct headers via the OPTIONS method.

If you're using nodejs and express, you can add something like this to your service:

app.use((req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
  res.header("Access-Control-Allow-Methods", "GET");

  if (req.method === "OPTIONS") return res.status(200).json({});


Or, there are plenty of CORS libraries that can help you out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.