Challenge - 5 Problems
Docker Mastery for Express
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when you run this Dockerfile?
Consider this Dockerfile for an Express app. What will be the output when you build and run the container?
Express
FROM node:18-alpine WORKDIR /app COPY package.json ./ RUN npm install COPY . . EXPOSE 3000 CMD ["node", "server.js"]
Attempts:
2 left
💡 Hint
Check the EXPOSE and CMD instructions and what they do.
✗ Incorrect
The Dockerfile sets the working directory, installs dependencies, copies files, exposes port 3000, and runs the app with node server.js. This means the app listens on port 3000 inside the container.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this Dockerfile snippet
Which option correctly identifies the syntax error in this Dockerfile snippet?
Express
FROM node:18 WORKDIR /app COPY package.json ./ RUN npm install COPY . . EXPOSE 3000 CMD [node server.js]
Attempts:
2 left
💡 Hint
Look at the CMD instruction format.
✗ Incorrect
CMD should be either an exec form array like ["node", "server.js"] or a shell form string. Writing CMD [node server.js] without quotes or commas causes a syntax error.
🔧 Debug
advanced2:00remaining
Why does the container fail to connect to the Express app?
You built and ran this Docker container, but your browser cannot connect to the Express app on localhost:3000. What is the most likely cause?
Express
Docker run command: docker run -d -p 3000:3000 my-express-app Express app listens on port 3000 Dockerfile exposes port 3000
Attempts:
2 left
💡 Hint
Check the network binding of the Express app inside the container.
✗ Incorrect
If Express listens only on 127.0.0.1, it is not reachable from outside the container. It must listen on 0.0.0.0 to accept external connections.
❓ state_output
advanced2:00remaining
What is the value of NODE_ENV inside the container?
Given this Dockerfile snippet, what will be the value of NODE_ENV inside the running container?
Express
FROM node:18 ENV NODE_ENV=production WORKDIR /app COPY . . RUN npm install CMD ["node", "server.js"]
Attempts:
2 left
💡 Hint
Look at the ENV instruction in Dockerfile.
✗ Incorrect
The ENV instruction sets environment variables inside the container. NODE_ENV is set to production.
🧠 Conceptual
expert3:00remaining
Which option best explains the benefit of multi-stage builds in Docker for Express apps?
Why use multi-stage builds in Dockerfiles for Express applications?
Attempts:
2 left
💡 Hint
Think about image size and build vs runtime needs.
✗ Incorrect
Multi-stage builds let you install build tools and dependencies in one stage, then copy only the needed files to a smaller final image, reducing size and attack surface.