Challenge - 5 Problems
Astro Docker Deployment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat happens when you run this Dockerfile for an Astro project?
Consider this Dockerfile for an Astro project:
What will be the result when you build and run this Docker image?
FROM node:18-alpine WORKDIR /app COPY package.json package-lock.json ./ RUN npm install COPY . . RUN npm run build CMD ["npm", "start"]
What will be the result when you build and run this Docker image?
Astro
FROM node:18-alpine WORKDIR /app COPY package.json package-lock.json ./ RUN npm install COPY . . RUN npm run build CMD ["npm", "start"]
Attempts:
2 left
💡 Hint
Think about what npm run build does and what npm start expects in an Astro project.
✗ Incorrect
In Astro, npm run build creates static files in the 'dist' folder. The default npm start expects a server script, but this Dockerfile does not serve the static files properly. So the container will run but not serve the site correctly.
📝 Syntax
intermediateIdentify the syntax error in this Dockerfile snippet for Astro
Look at this Dockerfile snippet:
What is wrong with this Dockerfile?
FROM node:18-alpine WORKDIR /app COPY package.json package-lock.json ./ RUN npm install COPY . . RUN npm run build CMD npm start
What is wrong with this Dockerfile?
Astro
FROM node:18-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
CMD npm startAttempts:
2 left
💡 Hint
Check how CMD expects its arguments in JSON array form or string form.
✗ Incorrect
CMD expects either a JSON array with command and arguments or a single string. Writing CMD npm start without quotes or array causes a syntax error.
🔧 Debug
advancedWhy does this Docker container fail to serve the Astro site?
Given this Dockerfile:
The container builds successfully but when accessed, the site shows a 404 error. Why?
FROM node:18-alpine WORKDIR /app COPY . . RUN npm install RUN npm run build CMD ["npx", "serve", "dist"]
The container builds successfully but when accessed, the site shows a 404 error. Why?
Astro
FROM node:18-alpine WORKDIR /app COPY . . RUN npm install RUN npm run build CMD ["npx", "serve", "dist"]
Attempts:
2 left
💡 Hint
Does the Dockerfile install the 'serve' package anywhere?
✗ Incorrect
The Dockerfile does not install 'serve' as a dependency, so npx cannot find it to run. This causes the server to not start properly, leading to 404 errors.
❓ state_output
advancedWhat is the size difference between these two Docker images for Astro?
Compare these two Dockerfile snippets:
Image A:
Image B:
Which statement about their image sizes is true?
Image A:
FROM node:18-alpine WORKDIR /app COPY package.json package-lock.json ./ RUN npm install COPY . . RUN npm run build CMD ["npx", "serve", "dist"]
Image B:
FROM node:18-alpine AS builder WORKDIR /app COPY package.json package-lock.json ./ RUN npm install COPY . . RUN npm run build FROM nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html CMD ["nginx", "-g", "daemon off;"]
Which statement about their image sizes is true?
Attempts:
2 left
💡 Hint
Think about multi-stage builds and what files end up in the final image.
✗ Incorrect
Image B uses a multi-stage build to copy only the static build output into a lightweight nginx image, making it smaller than Image A which includes node and all dependencies.
🧠 Conceptual
expertWhich Docker deployment approach best fits Astro's static site generation?
Astro generates static HTML files after build. Which Docker deployment method is best to serve an Astro site efficiently?
Attempts:
2 left
💡 Hint
Consider Astro's static output and Docker image size optimization.
✗ Incorrect
Astro produces static files best served by a simple web server. Multi-stage builds allow building with node then serving with nginx, reducing image size and improving performance.
