0

I'm trying to build a container for an app I'm building using docker. The app works locally before containerization. After building a dockerfile I was able to successfully create an image and start a container from that. However when i go to localhost:5173 (default port from vite) nothing shows even though i bind that port to the exposed port within my dockerfile. I'm not getting any errors via docker when creating the image or container to look into.

Below is the current code for my dockerfile

FROM node:18.14

WORKDIR /user/src/app/visualizer

COPY . /user/src/app/

COPY package*.json /user/src/app/visualizer

RUN npm ci

EXPOSE 4000

ENTRYPOINT npm run dev

And this is the code for my package.json

{
    "name": "",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "dev": "vite dev",
        "build": "vite build",
        "preview": "vite preview",
        "test": "npm run test:integration && npm run test:unit",
        "lint": "prettier --plugin-search-dir . --check . && eslint .",
        "format": "prettier --plugin-search-dir . --write .",
        "test:integration": "playwright test",
        "test:unit": "vitest"
    },
    "devDependencies": {
        "@playwright/test": "^1.28.1",
        "@sveltejs/adapter-auto": "^2.0.0",
        "@sveltejs/kit": "^1.20.4",
        
        "autoprefixer": "^10.4.14",
        "daisyui": "^3.2.1",
        "eslint": "^8.28.0",
        "eslint-config-prettier": "^8.5.0",
        "eslint-plugin-svelte": "^2.30.0",
        "postcss": "^8.4.24",
        "postcss-load-config": "^4.0.1",
        "prettier": "^2.8.0",
        "prettier-plugin-svelte": "^2.10.1",
        "svelte": "^4.0.0",
        "svelte-check": "^3.4.3",
        "tailwindcss": "^3.3.2",
        "vite": "^4.3.6",
        "vitest": "^0.32.2"
    },
    "type": "module",
    "dependencies": {
        "pocketbase": "^0.15.0-rc"
    }
}

And below is the file structure at the moment

Root | |-apps (Dockerfile lives here) | | | |-backend | |-visualizer | | | | | |-.sveltekit | | |-src | | |-static | | |-tests

I've tried editing the src locations in the dockerfile for some of the files thinking that I might have the paths down incorrectly. I also tried to RUN npm run build within the image but that had it building the image for 5+ minutes. I hit many errors on initial image building and the code above is what i have that actually allows the image to be built out.Those errors i had were mentioning vite and sveltekit but i think the npm ci covered those. I tried starting the container with docker run -d -p 5173:4000 and checked both localhost ports in chrome with nothing rendering on the screen. Docker ps confirms that I've got a container up and running. My understanding is that if i go to localhost:5173 it should connect to the container at 4000 and show my app.

  • Does [running a vite dev server inside a docker container](https://stackoverflow.com/questions/70012970/running-a-vite-dev-server-inside-a-docker-container) answer your question? – David Maze Jul 21 '23 at 00:15
  • does this help ? [vitereactdocker-not-working-in-container](https://stackoverflow.com/questions/74229258/vitereactdocker-not-working-in-container) – frank_lee Jul 21 '23 at 01:40

0 Answers0