Toni Joe
Toni Joe

Reputation: 8407

How to run Sveltekit app on docker container on localhost

I'm learning docker so I want to test a Sveltekit app locally on a docker container but I was unable to make it work. This is my setup:

# svelte.config.js

import adapter from '@sveltejs/adapter-node';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
       adapter: adapter()
   }
};

export default config;

# Dockerfile

FROM node:18-alpine AS build

WORKDIR /app
COPY package*.json .
RUN rm -rf node_modules
RUN rm -rf build
RUN npm install
COPY . .
RUN npm run build

FROM node:18-alpine AS run

WORKDIR /app
COPY --from=build /app/package.json ./package.json
COPY --from=build /app/build ./build
RUN npm install --production
ENTRYPOINT [ "node", "build" ]

# docker-compose.yaml

services:
   app:
    restart: always
    image: svelte-docker
    build:
      context: .
      dockerfile: Dockerfile
      target: run
    ports:
      - 3000:5050

After I run docker compose up -d and open localhost:3000, I get This site can’t be reached error.

I don't know what I did wrong. Any help would be appreciated and thanks

Upvotes: 5

Views: 2781

Answers (1)

Wiicolas
Wiicolas

Reputation: 381

Can you try replacing your last line with

ENTRYPOINT [ "node", "build" ]

the folder .build does not exist you are creating a folder simply named build using COPY --from=build /app/build ./build

Upvotes: 1

Related Questions