DockerFile for SvelteKit Application
Are you working with SvelteKit and ready to deploy? Having issues with containerizing your application for said deployment? Well, look no further, here’s a Dockerfile that works for SvelteKit apps that I’ve used on Digital Ocean, GCP, and AWS
FROM node:14-alpine as builderWORKDIR /appCOPY package.json package-lock.json ./RUN npm installCOPY . .RUN npm run buildFROM node:14-alpineUSER node:nodeWORKDIR /appCOPY — from=builder — chown=node:node /app/build ./buildCOPY — from=builder — chown=node:node /app/node_modules ./node_modulesCOPY — chown=node:node package.json .ENV PORT 3000EXPOSE 3000CMD [“node”,”build”]
Building & Running
sudo docker build — no-cache -t nameofthing .
or
sudo docker build — platform linux/amd64 — no-cache -t nameofthing .
I included the platform in the second build command because I started using an M1 laptop and ran into issues when building images and then pushing those images to third party cloud platforms like AWS.
Run
sudo docker run — restart=always — publish 3000:3000 — name=nameofthing -d nameofthing