If you want to deploy your app as standalone Node server, you can use adapter node.
pnpm add -D @sveltejs/adapter-node
Replace adapter-auto
import with adapter-node
.
import adapter from '@sveltejs/adapter-node';
FROM node:20-slim AS builder
WORKDIR /app
RUN npm install -g pnpm
COPY package.json /app/package.json
COPY pnpm-lock.yaml /app/pnpm-lock.yaml
RUN pnpm install
COPY . ./
RUN pnpm run build
FROM node:20-slim AS server
WORKDIR /app
COPY --from=builder /app/build /app/build
COPY --from=builder /app/package.json /app/package.json
RUN npm install -g pnpm
RUN pnpm install --prod --no-frozen-lockfile
EXPOSE 3000
CMD [ "HOST=0.0.0.0", "PORT=3000", "node", "build" ]
Build docker image:
docker build -t web .
Run the image:
docker run -p 3000:3000 web
If you rather like to use docker compose to run your docker image then create production.yml
file with below code.
services:
web:
build: .
restart: unless-stopped
ports:
- 3000:3000
command: sh -c "HOST=0.0.0.0 PORT=3000 node build"
Now run it with:
docker compose -f production.yml up --build --detach