1

I installed the svelte app with vite with the command npm init vite. Then i did my programming stuff and build a simple todo app.

The svelte dev server starts on port 3000

package.json:

{
  "name": "package",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
    "start": "vite serve"
  },
  "devDependencies": {
    "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
    "autoprefixer": "^10.4.7",
    "postcss": "^8.4.14",
    "svelte": "^3.44.0",
    "tailwindcss": "^3.1.4",
    "vite": "^2.9.9"
  },
  "dependencies": {
    "uuidv4": "^6.2.13"
  }
}

This is my Dockerfile

FROM node:16-alpine

WORKDIR /app

COPY ./ ./

RUN npm install
RUN npm i -g vite
RUN npm run build

EXPOSE 3000

CMD [ "npm", "start" ]

then i type in my terminal

docker build -t todo . following with docker run -p 80:3000 todo

In the Dockercontainer everything works and it says it is started:

enter image description here

The problem now is I can't access it over localhost port 80. I also tried it with port 3000 to be sure but it still doesn't work.

What am I missing?

Posts i tested and saw: https://devlinduldulao.pro/svelte-in-docker/ https://svelte-recipes.netlify.app/publishing/ How to put a Svelte app in a docker container?

Thanks in advance!

0szi
  • 318
  • 3
  • 14
  • 1
    the image you posted tells you "use --host to expose". try "RUN npm run build --host" (untested) – 2pha Jul 06 '22 at 17:40
  • thank you -- --host works and the the thing with putting host in vite config also worked – 0szi Jul 07 '22 at 07:41

0 Answers0