title: Docker Gatsby Strapi produces ECONNREFUSED 127.0.0.1:1337 error
body: <p>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 - <a href="https://strapi.io/blog/building-a-static-website-using-gatsby-and-strapi" rel="noreferrer">https://strapi.io/blog/building-a-static-website-using-gatsby-and-strapi</a>. All works well and I'm ready to move onto the next step and place the project into Docker to deploy.</p>
  
  <p>Getting Strapi and the Mongo DB instance up and running in Docker has been very simple, pretty much identical to this set up - <a href="https://strapi.io/documentation/3.0.0-beta.x/installation/docker.html" rel="noreferrer">https://strapi.io/documentation/3.0.0-beta.x/installation/docker.html</a>.</p>
  
  <p>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 </p>
  
  <blockquote>
    <p>ERROR #11321 PLUGIN</p>
    
    <p>"gatsby-source-strapi" threw an error while running the sourceNodes
    lifecycle: connect ECONNREFUSED 127.0.0.1:1337</p>
    
    <p>Error: connect ECONNREFUSED 127.0.0.1:1337</p>
  </blockquote>
  
  <p>The Strapi and Mongo services run fine from the same docker-compose.yml file, as can be seen below</p>
  
  <pre><code>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
  </code></pre>
  
  <p>My Dockerfile looks like this</p>
  
  <pre><code>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" ]
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Anyone have any ideas?</p>