Next Auth - Fetch Error after Running Docker Container

16 views Asked by At

I have a problem, when I run the project with npm run dev or npm start Next auth works correctly but if I dockerize the app, I'm getting fetch error. I could not find any solution. I checked that all values are tru for the .env files but I could not find any answers to figure out this problem.

Project Structure

--project
--docker-compoese.yml
---frontend
---fronend-Dockerfile
---backend
---backend-Dockerfile

Docker Compose Yaml

version: '3.8'

services:
  backend:
    build: 
      context: ./backend
      dockerfile: Dockerfile
    volumes:
      - ./backend:/app
    ports:
      - "8000:8000"
    environment:
      - PYTHONDONTWRITEBYTECODE=1
      - PYTHONUNBUFFERED=1
    command: python manage.py runserver 0.0.0.0:8000

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    volumes:
      - ./frontend:/app
      - /app/node_modules
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - NEXTAUTH_URL=http://localhost:3000
      - NEXTAUTH_SECRET=****
      - NEXT_PUBLIC_BASE_URL=http://localhost:8000
      - HOSTNAME=0.0.0.0
    command: npm start

.env files both (.env.local / .env.production)

NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=***
NEXT_PUBLIC_BASE_URL=http://localhost:8000

Frontend Dockerfile

# Use an official Node.js runtime as a parent image
FROM node:18

# Set environment variables
ENV NODE_ENV production



ENV HOSTNAME 0.0.0.0

ENV NEXTAUTH_URL http://localhost:3000
ENV NEXTAUTH_SECRET ***
ENV NEXT_PUBLIC_BASE_URL http://127.0.0.1:8000

# Set work directory
WORKDIR /app

# Install dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./

# If you are building your code for production
# RUN npm ci --only=production
# For development, you might want to use:
RUN npm install

# Bundle app source
COPY . .

# Next.js collects completely static pages at build time
RUN npm run build
 op
# Expose the port Next.js runs on
EXPOSE 3000

# Command to run the application
CMD ["npm", "start"]

In the above, You can find the my files and my project structure.

0

There are 0 answers