Docker Gatsby Strapi produces ECONNREFUSED 127.0.0.1:1337 error Docker Gatsby Strapi produces ECONNREFUSED 127.0.0.1:1337 error docker docker

Docker Gatsby Strapi produces ECONNREFUSED 127.0.0.1:1337 error


After going through the logs for the Gatsby container, I replaced my completed website with a plain Hello World instance so I could cross that off the list or potential obstacles. Gatsby proceeded to spin up successfully.

Changing some content in the gatsby-config.js file to contain data relating to the api resulted in the connection errors returning. Changing the apiURL value in the file from http://localhost:1337 to http://0.0.0.0:1337 didn't change anything.

A search for cross container connection issues on a Mac resulted in a lead which ended up working for me.

This question - https://github.com/docker/for-mac/issues/2705 - held the key. Changing the apiURL value to http://docker.for.mac.localhost:1337 allowed the APIs to connect between Strapi and Gatsby. The value didn't sit well with me as some colleagues use PCs so that didn't seem right. Further digging unearthed the apiURL value of http://host.docker.internal:1337 which worked. I'll test all this on the production build compared to the development build and see how it all holds up.