Containerizing React Django based application through Dockerfile

Containerizing React Django based application through Dockerfile

DevOps Blog:1

Β·

2 min read

Here we see how to build an image with the help of Dockerfile. Dockerfile are used to create an image, which is then containerized to run the application on various platforms.

Pre-requisites:

AWS Account with Docker installed on the server.

The following steps should be taken to ensure the success of this project:

Clone the NodeJs application's Github repository.

Understand the project's requirements and create a Dockerfile to support all required dependencies.

Create an image from the Dockerfile.

Docker image is used to create and run containers.

Examine the port mappings thoroughly (Whether it is open or not).

You will find your application running if you open the port using the AWS server's Public IP address(inside the security group).

Step 1: The git repository containing the react application is cloned to the local repository by using the command.

$ git clone <HTTPS link or path of GitHub repository>

Let's try writing our own Dockerfile to execute the application instead of using the one that is already included in the repository. The prerequisites listed in the requirements or readme file must be understood in order to generate a Dockerfile. If there is no such file and you are unable to ascertain the requirements, you must ask the developer for it.

Step 2: Create the Dockerfile using the format provided.

FROM <IMAGE:tag>Download the necessary IMAGE.

WORKDIR Set up app as the working directory.

COPY . /app The working directory app will receive a copy of the code from the current directory.

RUN Installs the necessary software in accordance with the specifications listed in the requirements file.

EXPOSE will reveal the necessary port number.

CMD will execute the entire script following the build phase.

Step 3: Run the command BUILD to build the image using Dockerfile.

$ docker build . -t <image_tag>

In this case, "." stands for the current working directory and "-t" for image tag. This command will create the image using the specified image tag.

Step 4: Using the run command to containerize the Docker image.

$ docker run -d -p 8001:8001 <docker_image:tag>

Here, "-p" stands for the port number and "-d" indicates for the daemon mode. The port number 8001 can be used to execute this command, which will containerize the Docker image in daemon mode.

Step 5: You may find your application running on the server by typing "Public IP of the Instance:8001" into your browser.

As shown in the header picture.

I sincerely hope that this project will benefit you and improve your resume. We appreciate you reading the article. If you find my blogs educational and entertaining, kindly like and follow. Let's grow and learn together:) - Nitesh Singh

Β