Consider a simple Svelte app served by a Docker container. The Dockerfile uses node:18-alpine as base and runs npm run build then npm run preview. The app has a button that increments a counter displayed on screen.
What happens when you open the app in a browser and click the button 3 times?
FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build CMD ["npm", "run", "preview"]
Think about what npm run preview does and how Svelte apps behave after build.
The Dockerfile builds the Svelte app and runs the preview server which serves the static built files. The counter is client-side JavaScript and increments normally on button clicks.
Choose the Dockerfile snippet that correctly installs dependencies, builds the app, and runs it in production mode.
Look for correct CMD syntax and proper copying order.
Option A uses JSON array syntax for CMD which is recommended. It copies package.json first to leverage Docker cache, installs dependencies, copies rest, builds, then runs preview.
The Dockerfile below builds a Svelte app but the container exits immediately after starting. What is the cause?
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD npm run previewCheck how CMD is written and how Docker interprets it.
Using CMD without JSON array runs the command in a shell but does not keep the container running properly. Using JSON array syntax keeps the process attached.
You build a Docker image for a Svelte app and run it. Then you change the source code locally but do not rebuild the image. What will the running container show?
Think about how Docker images and containers isolate files.
Docker containers run from the image snapshot. Changes outside the container do not affect the running container unless volumes are mounted.
Multi-stage builds are common in Dockerfiles for Svelte apps. Why is this approach used?
Consider what files are needed to run the app versus build it.
Multi-stage builds let you build the app in a full Node environment, then copy only the built static files into a lightweight image for running, making the image smaller and safer.