0
0
Dockerdevops~30 mins

Development vs production Dockerfiles - Hands-On Comparison

Choose your learning style9 modes available
Development vs Production Dockerfiles
📖 Scenario: You are working on a simple web application using Docker. You want to create two Dockerfiles: one for development with debugging tools and live reload, and one for production optimized for performance and smaller size.
🎯 Goal: Build two Dockerfiles named Dockerfile.dev and Dockerfile.prod with specific content for development and production environments.
📋 What You'll Learn
Create a Dockerfile.dev starting from python:3.12-slim image
Add installation of flask and debugpy in Dockerfile.dev
Create a Dockerfile.prod starting from python:3.12-alpine image
Add installation of only flask in Dockerfile.prod
Use CMD to run app.py in both Dockerfiles
💡 Why This Matters
🌍 Real World
Developers often need different Docker setups for development and production to optimize debugging and performance.
💼 Career
Understanding how to write and manage multiple Dockerfiles is essential for DevOps roles and software deployment pipelines.
Progress0 / 4 steps
1
Create the development Dockerfile
Create a file named Dockerfile.dev with these exact lines:
FROM python:3.12-slim
RUN pip install flask debugpy
COPY app.py /app.py
CMD ["python", "/app.py"]
Docker
Need a hint?

Use FROM to set the base image, RUN to install packages, COPY to add your app, and CMD to run it.

2
Create the production Dockerfile
Create a file named Dockerfile.prod with these exact lines:
FROM python:3.12-alpine
RUN pip install flask
COPY app.py /app.py
CMD ["python", "/app.py"]
Docker
Need a hint?

Use a smaller base image python:3.12-alpine and install only flask for production.

3
Add a comment explaining the difference
Add a comment at the top of Dockerfile.dev that says: # Development Dockerfile with debug tools and a comment at the top of Dockerfile.prod that says: # Production Dockerfile optimized for size
Docker
Need a hint?

Comments start with # and explain the purpose of each Dockerfile.

4
Display the content of both Dockerfiles
Print the content of Dockerfile.dev and Dockerfile.prod exactly as created, separated by a blank line.
Docker
Need a hint?

Use triple quotes to store multi-line strings and print() to display them.