0

I am trying to run my app with a docker but i cannot reach the app through localhost:5173 in browser when my docker is running. (I can reach this port when I run my app outside the docker.) I run docker build -t app . and then docker run -d -p 5173:5173 app

WORKDIR  /frontend

COPY package*.json ./

RUN npm install -g npm@latest

RUN npm install

COPY . .

EXPOSE 5173

CMD ["npm", "run", "dev"]

I am new to docker and have tried bunch of stuff I saw over internet and none of them worked: for example trying to reach the port with ip address of container instead of localhost. the docker log is this:

 > frontend@0.0.0 dev
2023-08-11 11:54:45 > vite
2023-08-11 11:54:45 
2023-08-11 11:54:47 
2023-08-11 11:54:47   VITE v4.4.9  ready in 1375 ms
2023-08-11 11:54:47 
2023-08-11 11:54:47   ➜  Local:   http://localhost:5173/
2023-08-11 11:54:47   ➜  Network: use --host to expose

and the ports are mapped like this: 5173/tcp 0.0.0.0:5173

PoonehM
  • 1
  • 1
  • Are you [running a vite dev server inside a docker container](https://stackoverflow.com/questions/70012970/running-a-vite-dev-server-inside-a-docker-container)? – David Maze Aug 12 '23 at 10:25
  • Does this answer your question? [Cannot open a React app in the browser after dockerising](https://stackoverflow.com/questions/56759017/cannot-open-a-react-app-in-the-browser-after-dockerising) – Audun Hilden Aug 12 '23 at 11:06
  • add `--net=host` to the command. try `docker run -d -p 5173:5173 --net=host app` – W.S. Aug 12 '23 at 12:07
  • or check https://github.com/vitejs/vite/discussions/3396 – W.S. Aug 12 '23 at 12:21
  • @DavidMaze yes I am. I am really beginner, but when I built my app with npm install -d create-react-app instead, my app was running on the docker in the expected way. I don't understand what is the problem. – PoonehM Aug 17 '23 at 20:42
  • @W.S. didn't work and thanks for the reference, it is helpful. – PoonehM Aug 17 '23 at 20:44

0 Answers0