- Create a simple python application containerized with a dockerfile.
- Demonstrate running your application within a docker container (using docker run terminal commands).
- Build a docker image in your CI/CD pipeline which will be pushed to Docker Hub or other container management service.
├── .github/
│ └── workflows/
│ └── cicd.yml # Define the GitHub Actions workflow for
│ # Checkout repository, Log in to Docker Hub,
│ # Build/Push Docker image
├── imgs/
├── .gitignore
├── app.py # Main Python Flask application
├── Dockerfile # Instructions for containerizing the app
├── Makefile # Automation for Docker commands
├── README.md # Project documentation
└── requirements.txt # Python dependencies
- Users input their weight (in kilograms) and height (in centimeters).
- The app calculates the BMI using the formula: BMI = weight / (height in meters)^2.
- Displays the BMI and the corresponding category (Underweight, Normal, Overweight, or Obesity).
- Access the application via a browser at http://127.0.0.1:5001.
- Enter your weight and height, then submit the form.
- The app calculates your BMI and displays it with the corresponding category.
Ensure that Docker is installed on your system.
git clone https://github.com/nogibjj/Xianjing_Huang_Mini_Proj_12.git
Use the make command to build the Docker image:
make build
Run the Flask application in a Docker container:
make run
The application will be accessible at: http://127.0.0.1:5001.
-
Flask App:
- Runs inside the container on port 5000 (--port=5000).
- Listens on all network interfaces (--host=0.0.0.0).
CMD ["flask", "run", "--host=0.0.0.0"]
is the same as
CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"]
since Flask runs on port
5000
by default.If your app needs to run on a different port, you can add
--port=<port>
. -
Docker Networking:
- Maps host machine's port 5001 to container's port 5000 (-p 5001:5000).
-
Access the App:
- Open http://127.0.0.1:5001 in your browser to interact with the app running inside the container.
Set up the following secrets in your GitHub repository under Settings > Secrets and variables > Actions > Repository secrets
- DOCKER_USERNAME: Your Docker Hub username.
- DOCKER_PASSWORD: Your Docker Hub password or access token.
CI/CD steps:
- Checkout repository
- Log in to Docker Hub
- Build Docker image
- Push Docker image
Here is where you can see the container image pushed to DockerHub: