This project is a full-stack web application template that combines React, Vite, Flask, and Docker Compose. It provides a development and deployment environment for building and serving a React frontend with Vite and a Flask backend within Docker containers. Additionally, it includes a Redis database service as a dependency.
Install Docker and Docker Compose. Keep the Docker running.
Clone the Repository: git clone docker-react && cd docker-react
- To run the application, execute
docker-compose up --buildin the project root. - Access the web application in your browser at http://localhost:80.
To stop the running containers, use the following command:
docker-compose downThis will stop and remove the containers, but it won't remove the built images. To remove the images as well when stopping the containers, use the following command:
docker-compose down --volumes --rmi allFor development purposes, you can use the --scale option to run multiple instances of the webapp service (useful for testing load balancing):
docker-compose up --scale webapp=3.
├── README.md
├── docker-compose.yml
├── docker-swarm
│ └── docker-stack.yml
├── docker-swarm-deployment.sh
├── kubernetes
│ └── webapp-deployment.yml
├── minikube-deployment.sh
├── terraform
│ └── main.tf
└── webapp
├── Dockerfile
├── app.py
└── templates
├── README.md
├── index.html
├── package.json
├── public
│ └── vite.svg
├── src
│ ├── App.css
│ ├── App.jsx
│ ├── assets
│ │ └── react.svg
│ ├── index.css
│ └── main.jsx
└── vite.config.js
-
React App Build (Node as Builder):
- The Dockerfile in the
webappdirectory first builds the React app using Node.js as a builder. It sets up the working directory, installs dependencies, and runs the build command.
- The Dockerfile in the
-
Flask App and Redis Service (Python as Base):
- The second part of the Dockerfile uses a Python base image to set up the Flask app. It copies the built React app from the previous stage into the
templatesdirectory. - Flask is installed, and the Redis database service is defined as a dependency. The environment variable
FLASK_APPis set toapp.py.
- The second part of the Dockerfile uses a Python base image to set up the Flask app. It copies the built React app from the previous stage into the
- The
docker-compose.ymlfile orchestrates the entire application. It defines two services:webapp(for the combined React and Flask app) andredis(for the Redis database). - The
webappservice is built from the Dockerfile in thewebappdirectory, exposing port 80 on the host. It depends on theredisservice.
- Local Deployment:
- RUN Below commands to build, push, init and run docker swarm.
- chmod +x docker-swarm-deployment.sh
- ./docker-swarm-deployment.sh
- To stop and remove deployment
docker stack rm webapp_stack
-
Local - Minikube:
-
GKE - deployment
- Assume we have a cloud connection.
- Terraform - to create the Kubernetes Cluster.
brew install terraform gcloud config set project development-404800 gcloud services enable container.googleapis.com gcloud container clusters create docker-react-k8s --num-nodes=1 gcloud components install gke-gcloud-auth-plugin gcloud container clusters get-credentials docker-react-k8s kubectl get nodes
gcloud container clusters delete docker-react-k8s
- 2 Stratergies
- use terraform to create dev, stage and prod cluster.
- use single cluster but namespaces for dev, stage and prod.
- Develop,
- Run tests
- Build the docker image.
- Tag the docker image with build tag
- Upload the docker image to container repo.
- Update the respective values.yml file with tag.
- Run helm - to deploy (upgrade only when changes in values.yml)