Nuxt3 Strapi4 in one Docker container | Error: connect ECONNREFUSED 127.0.0.1:1337

System Information
  • Strapi Version: 4.7.0-beta.0
  • Operating System: macOs 12.6.3
  • Database: sqlite
  • Node Version: 1.22.19
  • Yarn Version: v14.19.1

I’m running in a docker container called nuxtsrapi with two apps as two different images. one is a nuxt3 app in a folder named frontend on port 3000 the other is a strapi4 app in a backend on port 1337.
my strapi app is set up for sqlite as db and I’m using yarn.

My questions are:

  1. How can I be able to connect them so that when I run the container I won’t get the error: nuxtstrapi-frontend-1 | Error: connect ECONNREFUSED 127.0.0.1:1337
  2. How should set up my files do they will run a develop env on my local machine and production on a server

Here are some content of my docker files

Dockerfile in frontend

FROM node:14.19.1
WORKDIR /app/frontend
COPY package*.json ./
RUN yarn install
COPY . .
EXPOSE 3000
CMD ["yarn", "dev"]

Dockerfile in backend

FROM node:14.19.1
WORKDIR /app/backend
COPY package*.json ./
RUN yarn install
COPY . .
EXPOSE 1337
CMD ["yarn", "start"]

docker-compose.yml in root

version: '3'
services:
  frontend:
    build:
      context: ./frontend
    ports:
      - 3000:3000
  backend:
    build:
      context: ./backend
    ports:
      - 1337:1337
    environment:
      DATABASE_CLIENT: sqlite
      DATABASE_NAME: strapi
      DATABASE_HOST: backend
      DATABASE_PORT: 1337
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: strapi

1 Like

If your using docker-compose you need to put them in the same network :slight_smile:
You can use npx @strapi-community/dockerize from there add your frontend.

1 Like

thank you very much. I will try to put them in the same network.