0
0
Svelteframework~20 mins

Docker deployment in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Deployment Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will be the output when running this Dockerized Svelte app?

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?

Svelte
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD ["npm", "run", "preview"]
AThe app fails to load because the Dockerfile misses exposing port 3000.
BThe counter increments from 0 to 3 on button clicks, showing updated count each time.
CThe app shows the counter but button clicks do not update the count due to missing hot reload.
DThe app crashes on start because node_modules is not copied into the container.
Attempts:
2 left
💡 Hint

Think about what npm run preview does and how Svelte apps behave after build.

📝 Syntax
intermediate
2:00remaining
Which Dockerfile snippet correctly sets up a Svelte app for production?

Choose the Dockerfile snippet that correctly installs dependencies, builds the app, and runs it in production mode.

A
FROM node:18
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
CMD ["npm", "run", "preview"]
B
FROM node:18
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
CMD ["npm", "start"]
C
FROM node:18
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
CMD npm run preview
D
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
CMD npm run preview
Attempts:
2 left
💡 Hint

Look for correct CMD syntax and proper copying order.

🔧 Debug
advanced
2:00remaining
Why does this Dockerized Svelte app fail to start?

The Dockerfile below builds a Svelte app but the container exits immediately after starting. What is the cause?

Svelte
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD npm run preview
AThe CMD instruction is missing JSON array syntax, causing the container to exit immediately.
BThe app crashes because the build output folder is not copied.
CThe container exits because the port is not exposed in the Dockerfile.
DThe app fails because <code>npm run preview</code> is not installed in node_modules.
Attempts:
2 left
💡 Hint

Check how CMD is written and how Docker interprets it.

lifecycle
advanced
2:00remaining
What happens if you change source code after building the Docker image?

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?

AThe container shows a blank page because source and build files mismatch.
BThe container automatically updates to show the new source code changes.
CThe container crashes because source files changed but image is not rebuilt.
DThe container shows the old version of the app as it uses the built files inside the image.
Attempts:
2 left
💡 Hint

Think about how Docker images and containers isolate files.

🧠 Conceptual
expert
2:00remaining
Which statement best explains why multi-stage builds are used in Docker for Svelte apps?

Multi-stage builds are common in Dockerfiles for Svelte apps. Why is this approach used?

ATo allow running multiple Svelte apps in one container efficiently.
BTo enable hot module replacement inside the container during development.
CTo separate the build environment from the runtime environment, reducing final image size and attack surface.
DTo cache node_modules separately for faster rebuilds.
Attempts:
2 left
💡 Hint

Consider what files are needed to run the app versus build it.