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
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
You need to uncomment these last two lines:
stdin_open: true
andtty: true
because React app needs to be run in interactive modeThough 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.