Cannot get dockerize vite react application by going localhost:3000

83 Views Asked by At

I am new to Dockerizing by the way, and on top of that new to turborepo. This is a vite react typescript app inside a turborepo that is giving me nightmares, I just want to see the app and I can't! I am getting ERR_CONNECTION_RESET when going to localhost:3000. I appreciate your help in this.

Structure is:

|- apps
|----- client
|------------ ... other stuff
|------------ Dockerfile
|----- server (express with trpc i can access no issues to localhost:3001)
|------------ ... other stuff
|------------ Dockerfile
|- out
|- docker-compose.yml
|- turbo.json
|- package.json

This is the Dockerfile for the client app (the one with issues)

# BASE IMAGE
FROM node:18-alpine AS base

# BUILD STAGE
FROM base AS builder
WORKDIR /app
RUN npm install -g turbo
COPY . .
RUN turbo prune client --docker
RUN npm install

# build app
RUN turbo run build --filter=client...

# PRODUCTION STAGE
FROM base as production
WORKDIR /app
COPY --from=builder /app/out/full/apps/client/dist .
COPY --from=builder /app/out/full/apps/client/vite.config.ts .
COPY --from=builder /app/out/json/apps/client/package.json .
RUN npm install typescript

EXPOSE 3000
CMD ["npm", "run", "preview"]

And this is the docker-compose.yml

version: "3"

services:
  client:
    container_name: client
    build:
      context: .
      dockerfile: ./apps/client/Dockerfile
    restart: always
    ports:
      - 3000:3000
    networks:
      - app_network

  server:
     # config for server here

networks:
  app_network:

When I do docker ps i get:

CONTAINER ID   IMAGE                  COMMAND                  CREATED             STATUS          PORTS                                       NAMES
a98c4ff73e5c   personal-site-client   "docker-entrypoint.s…"   16 minutes ago      Up 2 seconds    0.0.0.0:3000->3000/tcp, :::3000->3000/tcp   client
19020ababe0e   personal-site-server   "docker-entrypoint.s…"   About an hour ago   Up 16 minutes   0.0.0.0:3001->3001/tcp, :::3001->3001/tcp   server

I have also tried what mentioned here. but I then get "HTTP ERROR 404" Is there something I am missing? Again, thanks!

0

There are 0 best solutions below