Skip to main content
Welcome back! In this task, we’ll set up and test our Flask application on your local machine before pushing it to our GitHub repository. We’ll use VS Code for development, write the application code, declare dependencies, and containerize with Docker.

Prerequisites


1. Update the README

Open README.md in VS Code and add a clear project title and description:
Use VS Code’s Markdown Preview (⌘+Shift+V / Ctrl+Shift+V) to verify formatting.
The image shows a Visual Studio Code interface with a README.md file open, describing a Docker Flask application written in Python to be deployed on GKE. The file is displayed in both markdown and preview modes.

2. Project File Structure


3. Create the Flask Application

Create app.py at the project root with the following code:
This defines a basic web server with one route (/) that returns a greeting.

4. Specify Dependencies

In requirements.txt, list your Python packages:
This tells pip which libraries to install inside the container.

5. Write the Dockerfile

Create Dockerfile and add:
Key steps:
  • Use a lightweight Python base image
  • Copy and install dependencies
  • Copy application code
  • Expose Flask on all network interfaces
If Flask does not auto-detect app.py, you can set the environment variable:
or change the CMD to:

Next Steps

With your files in place (README.md, app.py, requirements.txt, Dockerfile), you’re ready to build and run the Docker image locally:
Visit http://localhost:5000 to verify the “Hello, Simple Flask application” message.

Watch Video