0
0
Dockerdevops~30 mins

Consistent environments across teams in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Consistent environments across teams
📖 Scenario: Your team needs to ensure everyone uses the same software environment to avoid "it works on my machine" problems. Docker helps by packaging the app and its environment together.In this project, you will create a simple Docker setup for a Python app that prints a greeting. This will help your team run the app consistently on any computer.
🎯 Goal: Build a Dockerfile that sets up a Python environment, copies a Python script, and runs it inside a container. This ensures all team members run the same code with the same Python version and dependencies.
📋 What You'll Learn
Create a Python script named app.py that prints 'Hello from Docker!'
Write a Dockerfile that uses the official Python 3.12 image
Copy app.py into the Docker image
Set the container to run app.py when started
Build and run the Docker container to see the output
💡 Why This Matters
🌍 Real World
Teams use Docker to package apps with their environment so everyone runs the same setup, avoiding bugs caused by different software versions.
💼 Career
Knowing how to create Dockerfiles and run containers is a key skill for DevOps engineers and developers working in teams.
Progress0 / 4 steps
1
Create the Python script
Create a file named app.py with one line of code that prints exactly 'Hello from Docker!'.
Docker
Need a hint?

Use the print() function with the exact text inside single quotes.

2
Start the Dockerfile with Python base image
Create a file named Dockerfile and write the line FROM python:3.12 as the first line to use the official Python 3.12 image.
Docker
Need a hint?

The FROM instruction sets the base image for your Docker container.

3
Copy app.py and set the command
In the Dockerfile, add these two lines after FROM python:3.12: COPY app.py /app.py and CMD ["python", "/app.py"] to copy the script and run it.
Docker
Need a hint?

COPY moves your script into the image. CMD tells Docker what to run when the container starts.

4
Build and run the Docker container
Run these two commands in your terminal: docker build -t my-python-app . to build the image, then docker run my-python-app to run the container and see the output.
Docker
Need a hint?

Use docker build -t my-python-app . then docker run my-python-app. The output should be Hello from Docker!