Challenge - 5 Problems
Docker Vue Deployment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will be the output when running this Dockerfile for a Vue app?
Consider this Dockerfile for a Vue app. What will be the final behavior of the container when started?
Vue
FROM node:18-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build FROM nginx:stable-alpine COPY --from=build /app/dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
Attempts:
2 left
💡 Hint
Think about what the two stages in the Dockerfile do and what nginx serves.
✗ Incorrect
The first stage builds the Vue app into static files in /app/dist. The second stage copies these files into nginx's default html folder and serves them on port 80.
📝 Syntax
intermediate1:30remaining
Which Dockerfile snippet correctly copies the Vue build output to nginx?
You want to copy the Vue app build output from the build stage to nginx's html folder. Which COPY command is correct?
Attempts:
2 left
💡 Hint
Remember the build output folder inside the build stage.
✗ Incorrect
The Vue build output is in /app/dist inside the build stage. The COPY command must specify the source stage and the correct path.
🔧 Debug
advanced2:30remaining
Why does this Docker container fail to serve the Vue app?
Given this Dockerfile snippet, the container starts but shows a 404 error when accessed:
FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build /app /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Attempts:
2 left
💡 Hint
Check what nginx expects to serve and what files are copied.
✗ Incorrect
Nginx serves static files from /usr/share/nginx/html. Copying the entire /app folder includes source files and node_modules, not just the built static files in /app/dist. This causes nginx to serve wrong content and results in 404 errors.
❓ state_output
advanced1:30remaining
What environment variable should you set to change the base URL in a Vue app Docker build?
You want your Vue app to work correctly behind a subpath like /myapp/. Which environment variable should you set during build to adjust the base URL?
Attempts:
2 left
💡 Hint
Check Vue CLI documentation about base URL configuration.
✗ Incorrect
Vue CLI uses the environment variable BASE_URL to set the base path for the app during build. This affects how assets and routing paths are generated.
🧠 Conceptual
expert3:00remaining
Why use a multi-stage Docker build for Vue apps instead of a single stage?
What is the main advantage of using a multi-stage Dockerfile with a build stage and a separate nginx stage for deploying Vue apps?
Attempts:
2 left
💡 Hint
Think about what files are needed to run the app versus build it.
✗ Incorrect
Multi-stage builds let you use a full Node environment to build the app, then copy only the static files to a lightweight nginx image. This keeps the final image small and secure.