Code Monkey home page Code Monkey logo

containerization-of-a-react-front-end-and-flask-back-end-app's Introduction

Containerization-of-a-React-front-end-and-Flask-back-end-application

Using docker containers to containerize a web application and taking advantage of its deployment, scalability and reusability properties.

These are steps laid out in the FREE AWS Cloud Project Bootcamp which I am a part of as a student in the second Week. App Containerization by Andrew Brown

DISCLAIMER

So let's agree that you are using Gitpod or VsCode as your development environment and that you already have a Flask back-end app and a React front-end app ready to be containerized, or you can follow along by using the files and scripts in this repo.

Let's go

  • Step 1: Create a Dockerfile inside the Backend-Flask directory

    Inside the Dockerfile, you have specified the base image and added any necessary dependencies and packages required by your Flask. But if you want to run these, move into the working DIR of Backend-Flask, and run the following commands;.

RUN pip3 install -r requirements.txt to install all your dependencies

to RUN Flask..

CMD pythom3 -m flask run --host==0.0.0.0 --port=4567 let us breifly discuss certain parts of the command...

-python3(we are running python version 3)

--m(a module specifing to use the FLASK module)

---host=0.0.0.0(we are binding to 0.0.0.0, because we are trying to expose our application outside the scope of the environment that we are running, rather than default which is 27.0.0.1 the localhost)

---port=4567(we are telling it to start on port 4567)

Remember to open port 4567 from the port tab by the terminal tab, clicking the LOCK to open

you can append api/activities/home to the url of 404 page you get after you open port 4567 for backend, to get data;

Screenshot (688)

Screenshot (694)

  • Step 2: Build the Docker image for the Flask app

Move back to your root directory, and RUN;

``docker build -t  backend-flask ./backend-flask``

![Docker Build Output]( Screenshot (689) )

  • Step 3: Create a Dockerfile for the React app

In the root directory of your frontend-React app, create a new file “Dockerfile” Inside the Dockerfile, you have specified the base image and added any necessary dependencies and packages required by your React app. But if you want to run these, move into the working DIR of frontend-React, and run the following commands

RUN npm install

to start React CMD npm start

  • Step 4: Build the Docker image for the React app

Move back to your root directory, and RUN;

docker build -t frontend-react-js ./frontend-react-js

you can append api/activities/home to the url of 404 page you get after you open port 3000 for frontend, to get a frontend interface.

Screenshot (694)

After appending, output should be like this but without data of activities from the backend-flask app;

Screenshot (693)

  • Step 5: Create a Docker Compose file

Create a Docker Compose file in the root directory of your project. Name the file as “docker-compose.yml”. In the file, specify the services for the React and Flask apps, including the Docker images, ports, and volumes. You can see my docker-compose.yml file for the contents of the file. The purpose for tthis file is to build both the Backend-Flask and Frontend-React which was earier built.

  • Step 5: Run a docker compose command

Outputs are as follows with both 4567 and 3000 opened;

Screenshot (692)

Screenshot (693)

photo_2023-02-26_22-31-11

To check present active container images, run docker image command after every stage, I have here an output of the command after building the Backend-Flask.

Screenshot (690)

There, we have our docker container image !

Please, I would appreciate you feedback

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.