Instructions: Create a simple Python application containerized with a dockerfile. The goal here is to both demonstrate running your application within a docker container (using docker run terminal commands) but to also build a docker image in your CI/CD pipeline which will be pushed to Docker Hub or other container management service.
- Prepare the necesary configuration files like the Dockerfile, .devcontainer folder with Dockerfile & json (for running your code on Codespaces), Makefile, requirements.txt, and cicd.yml for GitHub Actions integration. Ensure that the requirements.txt lists all necessary packages (for example, flask).
- Create an app.py file where you add your Flask app code.
- Optionally, create a templates folder with a HTML file for the frontend of the app, and a static folder with a style.css file for styling the frontend.
- Create a Dockerfile to containerize the Flask app and run it on container port 5050.
- Set up your Makefile to build a container from the Docker image, log in to dockerhub (using your username and password), push the image to dockerhub using your credentials, and run the container (either locally or on Codespaces). This is what the output of the make commands looks like.
- When you run the container, you will get a localhost URL which you can use to open and use your app on your browser.
Here is where you can see the container image pushed to DockerHub:
Here is a screenshot of what the calculator app looks like on Codespaces:
Calculator app code (Flask, HTML, & CSS) taken from: https://www.tutorialspoint.com/python/building_a_web_based_calculator_with_flask.htm