I have been working with Strapi and Gatsby through the command line to get a website and CMS up and running, similar to this set up - https://strapi.io/blog/building-a-static-website-using-gatsby-and-strapi. All works well and I'm ready to move onto the next step and place the project into Docker to deploy.
Getting Strapi and the Mongo DB instance up and running in Docker has been very simple, pretty much identical to this set up - https://strapi.io/documentation/3.0.0-beta.x/installation/docker.html.
Problems arise when I try to get my Gatsby installation into Docker. I have tried a mountain of different configuration settings in the docker-compose.yml and Dockerfile but I keep running into the error of
ERROR #11321 PLUGIN
"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle: connect ECONNREFUSED 127.0.0.1:1337
Error: connect ECONNREFUSED 127.0.0.1:1337
The Strapi and Mongo services run fine from the same docker-compose.yml file, as can be seen below
version: "3"
services:
strapi:
image: strapi/strapi
environment:
DATABASE_CLIENT: mongo
DATABASE_NAME: strapi
DATABASE_HOST: mongo
DATABASE_PORT: 27017
DATABASE_USERNAME: strapi
DATABASE_PASSWORD: strapi
links:
- mongo:mongo
volumes:
- ./cms:/srv/cms
ports:
- "1337:1337"
mongo:
image: mongo
environment:
MONGO_INITDB_ROOT_USERNAME: strapi
MONGO_INITDB_ROOT_PASSWORD: strapi
volumes:
- ./db/db:/db/db
ports:
- "27017:27017"
gatsby:
image: docker-gatsby-client
build: ./website
command: gatsby develop -H 0.0.0.0
volumes:
- ./website:/usr/src/app/website
- /usr/src/app/website/node_modules
ports:
- "8000:8000"
depends_on:
- strapi
- mongo
environment:
GATSBY_WEBPACK_PUBLICPATH: /
STRAPI_URL: strapi:1337
My Dockerfile looks like this
FROM node:12
WORKDIR /usr/src/app/website
COPY package*.json ./
RUN npm install
RUN npm install -g gatsby-cli
RUN npm install --save gatsby-source-strapi
COPY . .
EXPOSE 8000
CMD ["yarn", "develop", "-H", "0.0.0.0" ]
I have tried lots of different settings in the compose file, like not using volumes, and also the Dockerfile, Like using different node versions. None of them work and all return the same error above.
If I run the Gatsby service from the command line, it connects to the Strapi service from the Docker container and all is good with the world. That makes me think there is a setting not set right with the Gatsby service in Docker which is producing the connection error.
Anyone have any ideas?