0
0
Expressframework~20 mins

Docker containerization in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Mastery for Express
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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"]
AThe container starts and the Express app listens on port 3000 inside the container.
BThe container builds but crashes immediately because server.js is missing.
CThe container starts but the app listens on port 80 by default.
DThe container fails to build because the WORKDIR is missing a slash.
Attempts:
2 left
💡 Hint
Check the EXPOSE and CMD instructions and what they do.
📝 Syntax
intermediate
2: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]
ACOPY . . is invalid because it needs a destination folder.
BRUN npm install is invalid because it should be RUN npm install -g.
CEXPOSE 3000 is invalid because it must be EXPOSE "3000".
DCMD [node server.js] is invalid because CMD requires an array or a string with exec form.
Attempts:
2 left
💡 Hint
Look at the CMD instruction format.
🔧 Debug
advanced
2: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
AThe container port 3000 is mapped to host port 80, so you must use localhost:80.
BThe Dockerfile EXPOSE command is missing, so port 3000 is not open.
CThe Express app is listening only on localhost (127.0.0.1) inside the container, so external connections fail.
DThe docker run command is missing the -it flag, so the app does not start.
Attempts:
2 left
💡 Hint
Check the network binding of the Express app inside the container.
state_output
advanced
2: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"]
A"production"
B"development"
Cundefined
D"NODE_ENV"
Attempts:
2 left
💡 Hint
Look at the ENV instruction in Dockerfile.
🧠 Conceptual
expert
3: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?
AThey allow running multiple Express apps in one container simultaneously.
BThey reduce the final image size by separating build dependencies from runtime dependencies.
CThey enable hot-reloading of Express code inside the container without rebuilding.
DThey automatically update the Node.js version inside the container at runtime.
Attempts:
2 left
💡 Hint
Think about image size and build vs runtime needs.