skip to Main Content

I have the following Dockerfile for the server: `FROM node:18.13.0

WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
EXPOSE 8080    
CMD [ "npm", "run", "start"]

and for the client:

FROM node:18.13.0
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
EXPOSE 3000    
CMD ["npm", "start"]

and the docker-compose.yml

version: "3.8"

services:
  server:
    build: ./server
    container_name: e_commerce_server_container
    ports:
      - 8080:8080
    volumes:
      - ./server:/app
      - /app/node_modules

  client:
    build: ./client
    container_name: e_commerce_client_container
    ports:
      - 3000:3000
    volumes:
      - ./client:/app
      - /app/node_modules
    # stdin_open: true
    # tty: true

when I run docker-compose up --build and try to access the server on localhost:8080 is working, but for localhost:3000 to see my react app is not working.

What should I do? I’ve tried a lot of methods but noting.

3

Answers


  1. Chosen as BEST ANSWER

    I fixed the issue. It looks like it was from vite, I should add the "vite --host 0.0.0.0" and now it works


  2. You need to uncomment these last two lines:

    stdin_open: true and tty: true because React app needs to be run in interactive mode

    version: "3.8"
    
    services:
      server:
        build: ./server
        container_name: e_commerce_server_container
        ports:
          - 8080:8080
        volumes:
          - ./server:/app
          - /app/node_modules
    
      client:
        build: ./client
        container_name: e_commerce_client_container
        ports:
          - 3000:3000
        volumes:
          - ./client:/app
          - /app/node_modules
        stdin_open: true
        tty: true
    
    Login or Signup to reply.
  3. Though you have solved it, I guess better approach would be to generate build artifacts and serve them statically from the back-end server or through nginx server unless you are taking this approach intentionally.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search