0
0
Microservicessystem_design~20 mins

Dockerfile for microservices - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dockerfile Master for Microservices
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Docker build command?

Given the following Dockerfile for a Node.js microservice, what will be the output when running docker build -t myservice .?

Microservices
FROM node:18-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["node", "server.js"]
ASuccessfully built image with tag 'myservice' and no errors
BError: 'package.json' not found during COPY step
CError: npm install failed due to missing package.json
DBuild hangs indefinitely at RUN npm install
Attempts:
2 left
💡 Hint

Check if the Dockerfile copies package.json before running npm install.

Configuration
intermediate
1:30remaining
Which Dockerfile snippet correctly sets environment variables for a microservice?

Choose the Dockerfile snippet that correctly sets environment variables PORT to 8080 and NODE_ENV to production.

AENV PORT 8080 NODE_ENV production
BENV PORT:8080 NODE_ENV:production
CENV PORT=8080 NODE_ENV=production
DENV PORT=8080; NODE_ENV=production
Attempts:
2 left
💡 Hint

Look for the correct syntax to set multiple environment variables in one ENV instruction.

Troubleshoot
advanced
2:30remaining
Why does this Dockerfile cause a large image size?

Consider this Dockerfile for a Python microservice:

FROM python:3.12
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]

Why might this Docker image be larger than necessary?

AIt does not specify a user, causing permission issues
BIt uses an outdated Python base image
CIt runs pip install without caching dependencies
DIt copies all files including unnecessary ones like tests and docs
Attempts:
2 left
💡 Hint

Think about what files get included in the image when using COPY . ..

🔀 Workflow
advanced
3:00remaining
What is the correct order of Dockerfile instructions for efficient caching?

Arrange these Dockerfile instructions in the best order to optimize Docker layer caching for a Node.js microservice:

A1,2,3,4
B2,1,3,4
C3,1,2,4
D1,3,2,4
Attempts:
2 left
💡 Hint

Think about which files change most often and how Docker caches layers.

Best Practice
expert
2:30remaining
Which Dockerfile practice improves security for microservices?

Which option shows the best Dockerfile practice to improve security by avoiding running the container as root?

AUSER node
BRUN adduser appuser && USER appuser
CUSER 1000
DRUN chmod 777 /app && USER root
Attempts:
2 left
💡 Hint

Consider creating a non-root user and switching to it.