<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Imon Bayazid on Medium]]></title>
        <description><![CDATA[Stories by Imon Bayazid on Medium]]></description>
        <link>https://medium.com/@imonbayazid?source=rss-c9499a923db2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MhDw0vpyPUmBguaV6MGmNA.jpeg</url>
            <title>Stories by Imon Bayazid on Medium</title>
            <link>https://medium.com/@imonbayazid?source=rss-c9499a923db2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:58:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@imonbayazid/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Dockerizing applications with best practices (part-3)]]></title>
            <link>https://medium.com/@imonbayazid/dockerizing-applications-with-best-practices-part-3-8eb09454e0e6?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8eb09454e0e6</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:59:07 GMT</pubDate>
            <atom:updated>2022-04-17T09:59:07.154Z</atom:updated>
            <content:encoded><![CDATA[<p>In this section, we keep our source codes in our local system and then will build and run the application completely in docker. Even if we change our code from our local system, it will be reflected automatically and in the browser via rebuilding the docker image immediately.</p><p><strong>Follow the below instructions:</strong></p><ol><li>Install node,angular CLI in your local PC</li><li>Get angular project<br>ng new YOUR_APP_NAME<br>cd YOUR_APP_NAME<br>example:<br>ng new angular-docker-demo<br>cd angular-docker-demo</li><li>Create a docker file with the following content</li></ol><blockquote>FROM node:slim as build</blockquote><blockquote># install dependencies first, in a different location for easier app bind mounting for local development</blockquote><blockquote># due to default /home permissions we have to create the dir with root and change perms</blockquote><blockquote>RUN mkdir /home/app &amp;&amp; chown node:node /home/app</blockquote><blockquote>WORKDIR /home/app</blockquote><blockquote>RUN npm install -g @angular/cli</blockquote><blockquote># the official node image provides an unprivileged user as a security best practice</blockquote><blockquote># but we have to manually enable it. We put it here so npm installs dependencies as the same</blockquote><blockquote># user who runs the app.</blockquote><blockquote># <a href="https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user">https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user</a></blockquote><blockquote>USER node</blockquote><blockquote>COPY package.json package-lock.json* ./</blockquote><blockquote>RUN npm install --no-optional &amp;&amp; npm cache clean --force</blockquote><blockquote>ENV PATH /home/app/node_modules/.bin:$PATH</blockquote><blockquote># copy in our source code last, as it changes the most</blockquote><blockquote>COPY --chown=node:node . .</blockquote><blockquote>CMD ng serve --host 0.0.0.0</blockquote><p>To understand ‘–chown=node:node’<br>chown root /u<br>means change the owner of /u to “root”.<br>chown root:staff /u<br>Likewise, but also change its group to “staff”.</p><p>4. Create a docker-compose file</p><blockquote>version: &#39;3&#39;</blockquote><blockquote>services:</blockquote><blockquote>angdockdemo:</blockquote><blockquote>build:</blockquote><blockquote># . means the relative path; in this case the root directory where the docker-compose file exists</blockquote><blockquote>context: .</blockquote><blockquote># the dockerfile that u want to use to create the image</blockquote><blockquote>dockerfile: Dockerfile</blockquote><blockquote># user defined container name</blockquote><blockquote>container_name: ang_container</blockquote><blockquote>ports:</blockquote><blockquote>- 4242:4200</blockquote><blockquote>volumes:</blockquote><blockquote># map host(PC) current directory files to a docker container directory so that if we change something in our host(PC) system it will refect our docker images</blockquote><blockquote>- .:/home/app</blockquote><blockquote># a named volume for node_modules so that we don&#39;t need to create</blockquote><blockquote>- /home/app/node_modules</blockquote><p>5. Create a .dockerignore file with the following content<br>dist<br>node_modules<br>.git<br>.gitignore<br>.env</p><p>This will prevent docker to copy(override) our local node_modules into docker. As we want to build and run inside our docker, we don’t want to use our local node_modules files.</p><p>6. To check whether everything is working or not<br>Just run<strong> docker-compose up</strong><br>and goto http://localhost:4242<br>Change something in the source file from the local (PC) and again goto <a href="http://localhost:4242/">http://localhost:4242</a><br>you will see the change in the browser which is shown from the docker container.</p><p>7. We can simply build by<br>docker build -t your_image_name .<br>or we can tag the image while building as it is necessary to tag the image when u want to push it in the docker hub<br>so we will use<br>docker build -t your_dockerhub_username/your_image_name :version_name .<br>example: docker build -t imonbayazid/angular-docker-way3:v1 .</p><p>8. check docker images in the docker<br>docker images</p><p>9. Run the docker image<br>docker run --name your_container_name-p 4200:4200 -d your_dockerhub_username/your_image_name :version_name<br>example: docker run --name angular-docker-way3-container -p 4200:4200 -d imonbayazid/angular-docker-way3:v1</p><p>10. check the running container and its port<br>docker ps -a</p><p>11. check the localhost:port</p><p>12. Now push the docker image that we just built to the docker hub.<br>So, firstly login to your docker hub account.<br>docker login -u your_dockerhub_username<br>then just push the image<br>docker push your_dockerhub_username/your_image_name :version_name</p><p>13. Now to check whether your image works or not, pull the image from the dockerhub and run it.<br>First, remove the image that you run previously also remove the container.<br>docker rm -f YOUR_DOCKER_CONTAINER_ID<br>docker rmi -f YOUR_DOCKER_IMAGE_ID</p><p>Now pull the image from the dockerhub<br>docker pull your_dockerhub_username/your_image_name :version_name</p><p>Check the image<br>docker images</p><p>Lastly, run the image like before.<br>docker run --name your_container_name-p 4200:4200 -d your_dockerhub_username/your_image_name :version_name</p><p>check the running container and its port<br>docker ps -a</p><p>14. check the localhost:4200</p><p><a href="https://github.com/imonbayazid/angular-docker-with-best-practice/tree/master/Sample%20Projects/angular-docker-way3">GitRepo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8eb09454e0e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerizing applications with best practices (part-2)]]></title>
            <link>https://medium.com/@imonbayazid/dockerizing-applications-with-best-practices-part-2-fdd131655bc2?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdd131655bc2</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:55:58 GMT</pubDate>
            <atom:updated>2022-04-17T09:55:58.565Z</atom:updated>
            <content:encoded><![CDATA[<p>In this part, we will implement the 2nd scenario.<br>We will build and run the application inside the docker using a ngix server.</p><p><strong>Follow the below steps:</strong><br>Please read all the comments where you will find all the explanations.</p><ol><li>Install node, angular CLI in your local PC</li><li>Get angular project<br>ng new YOUR_APP_NAME<br>cd YOUR_APP_NAME<br>example:<br>ng new angular-docker-demo<br>cd angular-docker-demo</li><li>Create a docker file with the following content</li></ol><blockquote>#STAGE 1: Build Stage</blockquote><blockquote>#slim version of node is highly recommended</blockquote><blockquote>FROM node:slim as build_stage</blockquote><blockquote>#set working directory in the container where all our local files will be copied and run. If the directory is not found then docker will create it</blockquote><blockquote>WORKDIR /home/app</blockquote><blockquote>#copy the package.json file from our local system(Pc) to the working directory(container)</blockquote><blockquote>COPY package.json package-lock.json* ./</blockquote><blockquote>#install npm packages (node_modules) in the container as we will build and run the application in the container</blockquote><blockquote>RUN npm install</blockquote><blockquote>#copy all the sources from the host(local PC) to the working directory of the container</blockquote><blockquote>COPY . .</blockquote><blockquote>#now have all source files and node_modules in our container, so build the project</blockquote><blockquote>RUN npm run build</blockquote><blockquote># In this stage, we have our production files in the dist folder. So, in the next step we will serve our application from dist folder of that container directory using a nginx server.</blockquote><blockquote>#STAGE 2: Run Stage###</blockquote><blockquote>FROM nginx:1.17.1-alpine</blockquote><blockquote>#copy the nginx config file from the host(local PC) to the nginx container specific location. This will configure our nginx server.</blockquote><blockquote>COPY nginx.conf /etc/nginx/nginx.conf</blockquote><blockquote>#copy the built files( from the dist folder) from our build_stage to the docker container</blockquote><blockquote>COPY --from=build_stage /home/app/dist/angular-docker-demo /usr/share/nginx/html</blockquote><p>4. create an Nginx. conf file with below contents where we specify the Nginx configuration along with its port, root and location.</p><blockquote>events{}</blockquote><blockquote>http {</blockquote><blockquote>include /etc/nginx/mime.types;</blockquote><blockquote>server {</blockquote><blockquote>listen 80; // you can define your own port here</blockquote><blockquote>server_name localhost;</blockquote><blockquote>root /usr/share/nginx/html;</blockquote><blockquote>index index.html;</blockquote><blockquote>location / {</blockquote><blockquote>try_files $uri $uri/ /index.html;</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><p>5. Create a .dockerignore file with the following content<br>dist<br>node_modules<br>This will prevent docker to copy(override) our local node_modules and dist files into docker. As we want to build, run and create a dist folder inside our docker, so we don’t want to use our local node_modules and dist files.</p><p>6. We are ready and can simply build our docker image by<br>docker build -t your_image_name .<br>or we can tag the image while building as it is necessary to tag the image when u want to push it in the docker hub<br>So we will use<br>docker build -t your_dockerhub_username/your_image_name :version_name .<br>example: docker build -t imonbayazid/angular-docker-way2:v1 .</p><p>7. Check docker images in the docker<br>docker images</p><p>8. Run the docker image<br>docker run --name your_container_name-p 80:80 -d your_dockerhub_username/your_image_name :version_name</p><p>example: docker run --name angular-docker-way2-container -p 8888:80 -d imonbayazid/angular-docker-way2:v1</p><p>9. check the running container and its port<br>docker ps -a</p><p>10. check the localhost: port</p><p>11. Now push the docker image that we just built to the docker hub.<br>So, the first login to your docker hub account.<br>docker login -u your_dockerhub_username<br>then just push the image<br>docker push your_dockerhub_username/your_image_name :version_name</p><p>12. Now to check whether your image works or not, pull the image from the docker hub and run it.<br>First, remove the image that you run previously also remove the container.<br>docker rm -f YOUR_DOCKER_CONTAINER_ID<br>docker rmi -f YOUR_DOCKER_IMAGE_ID</p><p>Now pull the image from the docker hub<br>docker pull your_dockerhub_username/your_image_name :version_name</p><p>Check the image<br>docker images</p><p>Lastly, run the image like before. You can map any port instead of 9090.<br>docker run --name your_container_name-p 9090:80 -d your_dockerhub_username/your_image_name :version_name</p><p>check the running container and it’s port<br>docker ps -a</p><p>13. check the localhost:9090</p><p>But there is some <strong>best practice</strong> to docker a node application.<br>Below is the sample docker file for dockerizing an angular application with best practices.</p><blockquote>### STAGE 1: Build Stage ###</blockquote><blockquote># slim version of node is highly recommended</blockquote><blockquote>FROM node:slim as build_stage</blockquote><blockquote># install dependencies first, in a different location for easier app bind mounting for local development</blockquote><blockquote># due to default /home permissions we have to create the dir with root and change perms</blockquote><blockquote>RUN mkdir /home/app &amp;&amp; chown node:node /home/app</blockquote><blockquote>WORKDIR /home/app</blockquote><blockquote># the official node image provides an unprivileged user as a security best practice</blockquote><blockquote># but we have to manually enable it. We put it here so npm installs dependencies as the same</blockquote><blockquote># user who runs the app.</blockquote><blockquote># <a href="https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user">https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user</a></blockquote><blockquote>USER node</blockquote><blockquote>COPY package.json package-lock.json* ./</blockquote><blockquote>RUN npm install --no-optional &amp;&amp; npm cache clean --force</blockquote><blockquote>ENV PATH /home/app/node_modules/.bin:$PATH</blockquote><blockquote># copy in our source code last, as it changes the most</blockquote><blockquote>COPY --chown=node:node . .</blockquote><blockquote>RUN npm run build</blockquote><blockquote>### STAGE 2: Run Stage###</blockquote><blockquote>FROM nginx:1.17.1-alpine</blockquote><blockquote>COPY nginx.conf /etc/nginx/nginx.conf</blockquote><blockquote>COPY --from=build_stage /home/app/dist/angular-docker-demo /usr/share/nginx/html</blockquote><p><a href="https://github.com/imonbayazid/angular-docker-with-best-practice/tree/master/Sample%20Projects/angular-docker-way2">GitRepo</a></p><p><a href="https://oloshprogrammer.wordpress.com/2020/06/16/dockerizing-applications-with-best-practice-part-3/">PART-3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdd131655bc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerizing applications with best practices (part-1)]]></title>
            <link>https://medium.com/@imonbayazid/dockerizing-applications-with-best-practices-part-1-c86a113f3317?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c86a113f3317</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:51:59 GMT</pubDate>
            <atom:updated>2022-04-17T09:51:59.029Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial series, we will learn how to dockerize an angular app with best practices with a docker file. Moreover, we will dockerize a full-stack application (angular app as front-end, spring-boot as a back-end, MongoDB as a database) where they can interact with each other.</p><p>We assume that you have some idea of what docker is and hence, we will jump to the implementation.</p><p>Let’s start.<br>Our current aim is to dockerize a simple angular app as a basic implementation.<br>We can use the docker container in both the development and production stages.<br>Here, we will discuss the development stage first.</p><p>There are several ways that we can use docker depending on our needs and situation.</p><ol><li>We can build our source code locally. If the application runs perfectly then we just generate production files in the dist folder. Our aim is to dockerize the application and publish the docker image to any docker repository like docker-hub. In future, for instance, the test team can download this docker image and run that docker image in their system and can test the application that you built. Here docker image uses the Nginx server to run the Angular application.</li><li>We can build and run the application inside the docker using a ngix server inside the docker. But the downside is that, if we change our source code, it won&#39;t reflect in the browser immediately unless we rebuild the docker image.</li><li>For development, instead of building and running the application in the local system, we can build and run it inside the docker. If we change any code, it will immediately reflect in the docker container and we can see the changed result in our browser.</li></ol><p>We will start the number 1 scenario, where we will build our source code locally and if everything works fine in our local system then we will generate production files in the dist folder.</p><p><strong>Follow the below steps:</strong></p><ol><li>Install node, angular CLI in your local PC</li><li>Create an angular project<br>ng new YOUR_APP_NAME<br>cd YOUR_APP_NAME</li><li>npm install [ as we will build and run our project locally so we need to install node_modules in our local system ]</li><li>ng build –prod [change your project as you need and if everything works fine then build the production-ready files in the dist folder]</li><li>Create a docker file with the following content [it will basically use an Nginx server to run our Angular application. First, it will copy files from our dist folder(from the local machine) and will create a directory in the container with ‘/usr/share/nginx/html’ and then finally past the dist files into the container directory.<br>FROM nginx:1.17.1-alpine<br>COPY nginx.conf /etc/nginx/nginx.conf<br>COPY /dist/YOUR_APP_NAME /usr/share/nginx/html</li><li>create an Nginx. conf file in the root directory with the following contents. It is basically a set port and the location where the server will run.</li></ol><blockquote>events{}</blockquote><blockquote>http {</blockquote><blockquote>include /etc/nginx/mime.types;</blockquote><blockquote>server {</blockquote><blockquote>listen 80; // you can define your own port here</blockquote><blockquote>server_name localhost;</blockquote><blockquote>root /usr/share/nginx/html;</blockquote><blockquote>index index.html;</blockquote><blockquote>location / {</blockquote><blockquote>try_files $uri $uri/ /index.html;</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><p>7. We are ready and can simply build our docker image by<br>docker build -t your_image_name .<br>or we can tag the image while building as it is necessary to tag the image when u want to push it in the dockerhub.<br>Hence, we will use<br>docker build -t your_dockerhub_username/your_image_name :version_name .</p><p>8. Check docker images inside the docker<br>docker images</p><p>9. Run your newly built docker image<br>docker run --name your_container_name-p 80:80 -d your_dockerhub_username/your_image_name :version_name</p><p>10. As we run the docker image it will launch a container, so check the running container and its port<br>docker ps -a</p><p>11. Finally to check the output got to the localhost:port</p><p>12. If everything looks fine then push the docker image that we just built to the docker hub.<br>So, the first login to your docker hub account.<br>docker login -u your_dockerhub_username<br>then just push the image<br>docker push your_dockerhub_username/your_image_name :version_name</p><p>12. To check whether your image works or not, pull the image from the docker hub and run it.<br>First, remove the image that you run previously also remove the container as well.<br>docker rm -f YOUR_DOCKER_CONTAINER_ID<br>docker rmi -f YOUR_DOCKER_IMAGE_ID</p><p>13. Now pull the image from the docker hub<br>docker pull your_dockerhub_username/your_image_name :version_name</p><p>14. Check the existing images in your docker<br>docker images</p><p>Finally, run the image like before.<br>docker run --name your_container_name-p 80:80 -d your_dockerhub_username/your_image_name :version_name</p><p>check the running container and its port<br>docker ps -a</p><p>Check the localhost:80</p><p>Check all codes in my <a href="https://github.com/imonbayazid/angular-docker-with-best-practice/tree/master/Sample%20Projects/angular-docker-way1">git repo</a></p><p>Goto <a href="https://oloshprogrammer.wordpress.com/2020/06/16/dockerizing-applications-with-best-practice-part-2/">PART-2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c86a113f3317" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerization of a full-stack application (Spring, Angular, MongoDB) — part 3]]></title>
            <link>https://medium.com/@imonbayazid/dockerization-of-a-full-stack-application-spring-angular-mongodb-part-3-c114b97f286e?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c114b97f286e</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:46:03 GMT</pubDate>
            <atom:updated>2022-04-17T09:46:03.610Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dockerization of a full-stack application (Spring, Angular, MongoDB) — part 3</h3><p>So far we have created the frontend, and backend and also dockerized them.<br>Now, we want to run both frontend and backend along with MongoDB and communicate with each other.<br>The frontend will send and receive data to the backend which is stored in MongoDB.</p><p>Our final project structure will be like the below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/0*fO2jy_fUkh-xb3pM.png" /></figure><p>In the backend folder, all the backend code along with the docker file will be there.<br>On the other hand, in the frontend folder, all the frontend codes along with its docker file will exist.</p><p>So, we will first create a docker-compose file with the following contents.</p><blockquote>version: &#39;3&#39;</blockquote><blockquote>services:</blockquote><blockquote>#************Mongo DB***************</blockquote><blockquote>database_mongo:</blockquote><blockquote>container_name: mongo_container</blockquote><blockquote>image: mongo:latest</blockquote><blockquote>hostname: asmd_mongo_host</blockquote><blockquote>environment:</blockquote><blockquote>- MONGO_INITDB_ROOT_DATABASE=asmd_mongo_db</blockquote><blockquote>volumes:</blockquote><blockquote>- ./mongodb_data_container:/data/db</blockquote><blockquote>#means you want to set data on container persist on your local folder named mongo-volume . /data/db/ is a folder that already created inside the mongo container.</blockquote><blockquote>ports:</blockquote><blockquote>- 27017:27017</blockquote><blockquote>networks:</blockquote><blockquote>- asmd_net</blockquote><blockquote>#************Backend***************</blockquote><blockquote>backend_spring:</blockquote><blockquote>container_name: spring_container</blockquote><blockquote>build:</blockquote><blockquote>context: ./Backend</blockquote><blockquote>dockerfile: Dockerfile</blockquote><blockquote>ports:</blockquote><blockquote>- 8080:8080</blockquote><blockquote>depends_on:</blockquote><blockquote>- database_mongo</blockquote><blockquote>networks:</blockquote><blockquote>- asmd_net</blockquote><blockquote>#************Frontend***************</blockquote><blockquote>frontend_angular:</blockquote><blockquote>container_name: angular_container</blockquote><blockquote>build:</blockquote><blockquote>context: ./Frontend</blockquote><blockquote>dockerfile: Dockerfile</blockquote><blockquote>ports:</blockquote><blockquote>- 4200:4200</blockquote><blockquote>networks:</blockquote><blockquote>- asmd_net</blockquote><blockquote>networks:</blockquote><blockquote>asmd_net:</blockquote><blockquote>driver: bridge</blockquote><p>It will build all the docker files and will the images for MongoDB, frontend and also backend.<br>Then just run the docker-compose up. It will build all projects and will run frontend, backend and MongoDB.<br>To check frontend, goto localhost:4200 and for the backend goto localhost:8080</p><p>Moreover, as we already uploaded all these images(mongo, frontend, backend) in our docker hub account, we can pull these images and run them together using a docker-compose file.<br>Hence, let’s create a separate docker-compose file using the below contents:</p><blockquote>version: &#39;3&#39;</blockquote><blockquote>services:</blockquote><blockquote>#************Mongo DB***************</blockquote><blockquote>database_mongo:</blockquote><blockquote>#if u run backend in the docker container then use this mongo_container as host name of the mongoDB config in the application.property file</blockquote><blockquote>container_name: mongo_container</blockquote><blockquote>image: imonbayazid/angularspringmongodocker_database_mongodb:v1</blockquote><blockquote>ports:</blockquote><blockquote>#if 27017 port is used in your system then change the first port</blockquote><blockquote>- 27017:27017</blockquote><blockquote>networks:</blockquote><blockquote>#mongo db and spring app should be under same network to communicate each other</blockquote><blockquote>- spring_mongo_angular_docker_net</blockquote><blockquote>#************Backend***************</blockquote><blockquote>backend_spring:</blockquote><blockquote>container_name: spring_container</blockquote><blockquote>image: imonbayazid/angularspringmongodocker_backend_spring:v1</blockquote><blockquote>ports:</blockquote><blockquote>- 8080:8080</blockquote><blockquote>depends_on:</blockquote><blockquote># make sure mongo db runs first before backend starts</blockquote><blockquote>- database_mongo</blockquote><blockquote>networks:</blockquote><blockquote>#mongo db and spring app should be under same network to communicate each other</blockquote><blockquote>- spring_mongo_angular_docker_net</blockquote><blockquote>#************Backend***************</blockquote><blockquote>frontend_angular:</blockquote><blockquote>container_name: angular_container</blockquote><blockquote>image: imonbayazid/angularspringmongodocker_frontend_angular:v1</blockquote><blockquote>ports:</blockquote><blockquote>- 4200:4200</blockquote><blockquote>networks:</blockquote><blockquote>#mongo db and spring app should be under same network to communicate each other</blockquote><blockquote>- spring_mongo_angular_docker_net</blockquote><blockquote>networks:</blockquote><blockquote>spring_mongo_angular_docker_net:</blockquote><blockquote>driver: bridge</blockquote><p>It will also do the same but instead of local files, it will use docker hub images that are already built and uploaded.</p><blockquote>Run docker-compose.yml to run both backend and frontend by building the docker files.<br>Run docker-compose-online.yml to run both backend and frontend by fetching the docker images which are already built and uploaded to the dockerhub.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c114b97f286e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerization of a full-stack application (Spring, Angular, MongoDB) — part 2]]></title>
            <link>https://medium.com/@imonbayazid/dockerization-of-a-full-stack-application-spring-angular-mongodb-part-2-44ce8155110?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/44ce8155110</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:43:45 GMT</pubDate>
            <atom:updated>2022-04-17T09:43:45.368Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dockerization of a full-stack application (Spring, Angular, MongoDB) — part 2</h3><p>In this part, we will create the backend project and will dockerize it.<br>We will create a simple spring-boot project which will have 2 APIs (getItems and addItem) to add a new item and to get all items. All the data will be saved in a MongoDB database.</p><p>All the codes can be found on <a href="https://github.com/imonbayazid/angular-spring-mongo-docker">Github</a>.</p><p>Our project will look like the below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/0*lHLs7V30gPMA4EEp.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_lDuFvk0hstV9j8k.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p7oiOmKn7OIthpf6.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-IwJ_WafKE_88QCi.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7u0aWrPvuznG0XuY.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aFDgd0TAK7p1qvsS.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FMtLE7BUt7EI7ci_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/0*-QyTRQcnpgu9HJIu.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wJ7SeUM_XLLcA1g6.png" /></figure><p>There are two practical scenarios to run a</p><ol><li>Run the spring-boot application locally; run MongoDB locally</li><li>Run the spring-boot application locally; run MongoDB inside the docker</li><li>Run spring-boot application inside the docker; run MongoDB inside the docker</li></ol><p><strong>[1]</strong> If we run both locally then we don&#39;t need to worry about the port and host of MongoDB. Just install and run mongo locally and run the spring app. Don&#39;t forget to add MongoDB in the pom.xml.<br>Spring will connect to the MongoDB via the default port of 27017 and also if you want to change the port then you can config this in the application.properties file or using the command line during running the spring-boot application.<br><strong>[2] </strong>If we want to run MongoDB in the docker and want to run the spring-boot application locally then we need to run the mongo image exposing the container via a port to the localhost.<br>In this case, the mongo container can talk/communicate to the localhost from the container.<br>For example:<br>docker run -p 27027:27017 –name mongodb_container mongo<br>It will fetch the mongo image and run a container at 27017 port in the docker. Then it will expose the container in the localhost via 27027 port.<br>So, to connect to MongoDB in such a case we have to define the specific mongo port(which we exposed from the container to localhost) in the application.properties file like<br>spring.data.mongo.port=27027<br>Now, if we run the spring-boot application then it can connect to MongoDB.</p><p><strong>[3]</strong> If we want to run the MongoDB in the docker and also want to run the spring-boot app inside the docker then first run the docker image of mongo like<br>docker run -p 27027:27017 –name mongodb_container mongo<br>Then use the mongo container name as the mongo host<br>For example, in the application.properties use<br>spring.data.mongo.host=mongodb_container<br>spring.data.mongo.port=27017<br>Also, they should be in the same network to communicate with each other. We can do this during running the docker image or we can use docker-compose file.<br>It is easy and good practice to use a docker-compose file in this case.</p><p>Instructions:</p><ol><li>Create a spring project</li><li>Add all your required changes and files</li><li>Build the spring project<br>mvn clean package &amp;&amp; java -jar target/app.jar<br>The package will compile your code and also package it. For example, if your pom says the project is a jar, it will create a jar for you when you package it and put it somewhere in the target directory (by default).</li><li>Create a docker file with</li></ol><blockquote>FROM openjdk:8</blockquote><blockquote>VOLUME /temp</blockquote><blockquote>ARG JAR_FILE=target/*.jar</blockquote><blockquote>COPY ${JAR_FILE} app.jar</blockquote><blockquote>EXPOSE 8080</blockquote><blockquote>ENTRYPOINT java -jar app.jar</blockquote><p>Basically, it will take the jar file(which we got by building the project in step 3)<br>and copy to the container finally then run the jar file at 8080 port.</p><p>5. Create a docker-compose with</p><blockquote>version: &#39;3&#39;</blockquote><blockquote>services:</blockquote><blockquote>#************Mongo DB***************</blockquote><blockquote>database_mongo:</blockquote><blockquote>container_name: mongo_container</blockquote><blockquote>image: mongo:latest</blockquote><blockquote>environment:</blockquote><blockquote>- MONGO_INITDB_ROOT_DATABASE=asmd_mongo_db</blockquote><blockquote>volumes:</blockquote><blockquote>- ./mongodb_data_container:/data/db</blockquote><blockquote>#means you want to set data on container persist on your local folder named mongo-volume . /data/db/ is a folder that already created inside the mongo container.</blockquote><blockquote>ports:</blockquote><blockquote>- 27017:27017</blockquote><blockquote>networks:</blockquote><blockquote>- asmd_net</blockquote><blockquote>#************Backend***************</blockquote><blockquote>backend_spring:</blockquote><blockquote>container_name: spring_container</blockquote><blockquote>build:</blockquote><blockquote>context: .</blockquote><blockquote>dockerfile: Dockerfile</blockquote><blockquote>ports:</blockquote><blockquote>- 8080:8080</blockquote><blockquote>depends_on:</blockquote><blockquote>- database_mongo</blockquote><blockquote>networks:</blockquote><blockquote>- asmd_net</blockquote><blockquote>networks:</blockquote><blockquote>asmd_net:</blockquote><blockquote>driver: bridge</blockquote><p>It will run all required docker and container.<br>Goto localhost:8080 and check the backend</p><p>Additionally, you can push the docker images to your docker hub.</p><p>6. If everything works well then remove the container and image</p><blockquote>docker rm -f CONTAINER_ID<br>docker rmi -f IMAGE_ID</blockquote><p>7. Now build the docker file with proper tagging to push it in the docker_hub.</p><blockquote>docker build -t YOUR_DOCKERHUB_USERNAME/YOUR_DOCKER_IMG_NAME:IMG_VERSION .</blockquote><p>8. Login to user docker account</p><blockquote>docker login -u your_dockerhub_username</blockquote><p>9. Push the newly built docker image to your docker hub account</p><blockquote>docker push YOUR_DOCKERHUB_USERNAME/YOUR_DOCKER_IMG_NAME:IMG_VERSION</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44ce8155110" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerization of a full-stack application (Spring, Angular, MongoDB) — part 1]]></title>
            <link>https://medium.com/@imonbayazid/dockerization-of-a-full-stack-application-spring-angular-mongodb-part-1-527ecf93c0da?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/527ecf93c0da</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:39:59 GMT</pubDate>
            <atom:updated>2022-04-17T09:39:59.149Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dockerization of a full-stack application (Spring, Angular, MongoDB) — part 1</h3><p>In this tutorial, we will show how to run a full stack project with Angular, Spring-boot, MongoDB and Docker.<br>All the codes can be found on <a href="https://github.com/imonbayazid/angular-spring-mongo-docker">Github</a>.</p><p>First, we will create a simple angular project which has a button. If we click the button it will send a request to the backend (spring-boot project) to add a new item and fetch all the items. After getting data it will show the fetched data in a list on the frontend.</p><p>Our final output for the frontend will look like the below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/0*NBFNfSX7Ud2Je-WQ.png" /></figure><p><strong>Follow the below steps:</strong></p><p>1. Install node, angular CLI in your local PC</p><p>2. Get angular project<br>ng new YOUR_APP_NAME<br>cd YOUR_APP_NAME</p><p>3. Change projects as you need and check locally</p><p>Edit app.component.html, app.component.ts and app. module like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/0*eWwGO6kUpilgF-_b.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/0*SLFBPXtdtodLOevN.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/0*PzNtW1lg1FkMFjiS.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*PawyjfEoClsPxBQJ.png" /></figure><p>4. Create a docker file with the following content</p><blockquote>FROM node:slim as build</blockquote><blockquote># install dependencies first, in a different location for easier app bind mounting for local development</blockquote><blockquote># due to default /home permissions we have to create the dir with root and change perms</blockquote><blockquote>RUN mkdir /home/app &amp;&amp; chown node:node /home/app</blockquote><blockquote>WORKDIR /home/app</blockquote><blockquote>RUN npm install -g @angular/cli</blockquote><blockquote># the official node image provides an unprivileged user as a security best practice</blockquote><blockquote># but we have to manually enable it. We put it here so npm installs dependencies as the same</blockquote><blockquote># user who runs the app.</blockquote><blockquote># <a href="https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user">https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user</a></blockquote><blockquote>USER node</blockquote><blockquote>COPY package.json package-lock.json* ./</blockquote><blockquote>RUN npm install --no-optional &amp;&amp; npm cache clean --force</blockquote><blockquote>ENV PATH /home/app/node_modules/.bin:$PATH</blockquote><blockquote># copy in our source code last, as it changes the most</blockquote><blockquote>COPY --chown=node:node . .</blockquote><blockquote>CMD ng serve --host 0.0.0.0</blockquote><p>5. Create a docker ignore file to avoid copying local node_modules into docker.</p><p>6. To check whether everything is working or not<br>Just run docker-compose up<br>and goto <a href="http://localhost:4242/">http://localhost:4242</a><br>Change something in the source file from the local (PC) and again goto <a href="http://localhost:4242/">http://localhost:4242</a><br>you will see the change in the browser which is shown from the docker container.</p><p>7. We can simply build by<br>docker build -t your_image_name .<br>or we can tag the image while building as it is necessary to tag the image when u want to push it in the dockerhub<br>so we will use<br>docker build -t your_dockerhub_username/your_image_name :version_name .<br>example: docker build -t imonbayazid/angular-docker-way3:v1 .</p><p>8. check docker images in the docker<br>docker images</p><p>9. Run the docker image<br>docker run –name your_container_name-p 4200:4200 -d your_dockerhub_username/your_image_name :version_name</p><p>10. check the running container and its port<br>docker ps -a</p><p>11. check the localhost: port</p><p>12. Now push the docker image that we just built to the docker hub.<br>So, firstly, log in to your docker hub account.<br>docker login -u your_dockerhub_username<br>then just push the image<br>docker push your_dockerhub_username/your_image_name :version_name</p><ol><li>now to check whether your image works or not, pull the image from the docker hub and run it.<br>First, remove the image that you run previously also remove the container.<br>docker rm -f YOUR_DOCKER_CONTAINER_ID<br>docker rmi -f YOUR_DOCKER_IMAGE_ID</li></ol><p>Now pull the image from the docker hub<br>docker pull your_dockerhub_username/your_image_name :version_name</p><p>Check the image<br>docker images</p><p>Lastly, run the image like before.<br>docker run –name your_container_name-p 4200:4200 -d your_dockerhub_username/your_image_name :version_name</p><p>check the running container and it’s port<br>docker ps -a</p><p>14. check the localhost:4200</p><p><strong>Shortcut Instruction</strong></p><ol><li>git clone this frontend folder</li><li>run docker-compose up<br>It will run the frontend only<br>(to check goto localhost:4200)<br>It will create a docker image named ‘frontend_asmd_frontend_service’<br>which u need to push to the docker_hub to use the image with the backend.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=527ecf93c0da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring boot JPA repository — work with any database (mongo, MySQL, Postgres,h2 etc)]]></title>
            <link>https://medium.com/@imonbayazid/spring-boot-jpa-repository-work-with-any-database-mongo-mysql-postgres-h2-etc-312f1e2656ea?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/312f1e2656ea</guid>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:34:25 GMT</pubDate>
            <atom:updated>2022-04-17T09:34:25.568Z</atom:updated>
            <content:encoded><![CDATA[<h3>Spring boot JPA repository — work with any database (mongo, MySQL, Postgres,h2 etc)</h3><p>In this tutorial, we will try to learn how to use the <strong>JPA repository</strong> in order to use any database in spring boot. We assume that you have some knowledge of how spring boot works.<br>Anyways, you can connect any database you want(mongo, MySQL, Postgres,h2 etc) by simply adding a dependency in the <em>pom.xml</em> and setting some configuration in the <em>application.properties </em>file.<br>We assume you have connected to any database.<br>Now, we need to create a traditional table in that database. In spring, we just need to define a model class and add the ‘<em>@Entity</em>‘ annotation before that class. Spring boot will automatically create a table if it finds a <em>@Entity</em> annotation before a class. Moreover, If you want to run some query, for example, if you want to pre-load(insert) some data then make a file named <em>data.sql </em>in the resource folder. Spring boot will automatically run <em>data.sql</em> during the run time of the application.</p><blockquote>@Entity<br>public class Alien {<br>@Id<br>private int aid;<br>private String aname;<br>private String tech;<br>public int getAid() {<br>return aid;<br>}<br>public void setAid(int aid) {<br>this.aid = aid;<br>}<br>public String getAname() {<br>return aname;<br>}<br>public void setAname(String aname) {<br>this.aname = aname;<br>}<br>public String getTech() {<br>return tech;<br>}<br>public void setTech(String tech) {<br>this.tech = tech;<br>}</blockquote><blockquote>}</blockquote><p>From the controller, you can call any method from the JPA repository.<br>By default, the JPA repository has some methods which you don&#39;t need to define. For example, findAll, findByID,save,delete.<br>Moreover, you can define your own method by following a pattern which is ‘findByPropertyName’</p><blockquote>@Controller</blockquote><blockquote>public class AlienController</blockquote><blockquote>{</blockquote><blockquote>@Autowired</blockquote><blockquote>AlienRepo repo;</blockquote><blockquote>@RequestMapping(&quot;/&quot;)</blockquote><blockquote>public String home()</blockquote><blockquote>{</blockquote><blockquote>return &quot;home.jsp&quot;;</blockquote><blockquote>}</blockquote><blockquote>@RequestMapping(&quot;/addAlien&quot;)</blockquote><blockquote>public String addAlien(Alien alien)</blockquote><blockquote>{</blockquote><blockquote>repo.save(alien);</blockquote><blockquote>return &quot;home.jsp&quot;;</blockquote><blockquote>}</blockquote><blockquote>@RequestMapping(&quot;/aliens&quot;)</blockquote><blockquote>@ResponseBody</blockquote><blockquote>public List&lt;Alien&gt; getAliens()</blockquote><blockquote>{</blockquote><blockquote>return repo.findAll();</blockquote><blockquote>}</blockquote><blockquote>@RequestMapping(&quot;/alien/{aid}&quot;)</blockquote><blockquote>@ResponseBody</blockquote><blockquote>public Optional&lt;Alien&gt; getAlien(@PathVariable(&quot;aid&quot;)int aid)</blockquote><blockquote>{</blockquote><blockquote>return repo.findById(aid);</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><p>In the repository, we can create our custom method, even custom query to execute.<br>By default, <em>JpaRepository</em> converts the list into JSON using the <em>Jackson </em>library.</p><blockquote>public interface AlienRepo extends JpaRepository<br>{<br>List findByTech(String tech);<br>List findByAidGreaterThan(int aid);<br>@Query(&quot;from Alien where tech=?1 order by aname&quot;)<br>ListfindByTechSorted(String tech);<br>}</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=312f1e2656ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Important docker commands to work.]]></title>
            <link>https://medium.com/@imonbayazid/important-docker-commands-to-work-d69e55692e8e?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d69e55692e8e</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:31:00 GMT</pubDate>
            <atom:updated>2022-04-17T09:31:00.291Z</atom:updated>
            <content:encoded><![CDATA[<p>List of docker images<br>&gt; docker images</p><p>List of running docker containers<br>&gt; docker ps -a</p><p>Remove docker images<br>&gt; docker rmi -f <em>IMAGE_ID</em></p><p>Remove docker container<br>&gt; docker rm -f <em>CONTAINER_ID</em></p><p>Build docker image<br>&gt;docker build -t your_dockerhub_username/your_image_name :version_name .</p><p>Run docker image<br>&gt;docker run your_image_name<br>or<br>&gt;docker run --name your_container_name -p 8081:8080 -d your_image_name<br>or<br>&gt;docker run -it --rm -p 9898:4200 --name your_container_name img_name<br>It will automatically remove the container when it is stopped.</p><p>-p: This publishes the port on the container and maps it to a port on our host. We will use port 80 on the host, but you should feel free to modify this as necessary if you have another process running on that port. For more information about how this works, see this discussion in the Docker docs on <a href="https://docs.docker.com/v17.09/engine/userguide/networking/default_network/binding/">port binding</a>.<br>-d: This runs the container in the background.<br>–name: This allows us to give the container a memorable name.</p><p>Inspect docker container<br>&gt;docker inspect container_ID</p><p>Check files inside a docker container<br>&gt;docker exec -t -i mycontainername /bin/bash</p><p>Check files inside the docker image<br>&gt;docker run -it image_name sh<br>Then you can check the current directory of containers or image<br>&gt;pwd<br>Also, you can list files of container/img<br>&gt;ls<br>To exit from that terminal<br>&gt;exit</p><p>For checking container logs if something doesn’t work<br>&gt;docker logs YOUR_CONTAINER_NAME</p><p><strong>To remove everything (container/image)</strong>:<br>Stop all running containers<br>&gt;docker stop $(docker ps -aq)<br>Remove all containers<br>&gt;docker rm $(docker ps -aq)<br>Remove all images<br>&gt;docker rmi $(docker images -q)<br>OR<br>&gt;docker container rm -f $(docker container ls -qa)<br>&gt;docker image rm -f $(docker image ls -q)</p><p>Tag your image before push<br>&gt;docker tag IMAGE_ID your_dockerhub_username/IMG_NAME:version</p><p>Push image to docker hub<br>&gt;docker push your_dockerhub_username/IMG_NAME:version</p><p>Pull image from docker hub<br>&gt;docker pull your_dockerhub_username/your_image_name :version_name</p><p>Login docker account<br>&gt;docker login -u your_dockerhub_username</p><p>The following builds the images if the images do not exist and starts the containers:<br>&gt;docker-compose up<br>If you add the –build option, it is forced to build the images even when not needed:<br>&gt;docker-compose up --build<br>If you want to skip the build process<br>&gt;docker-compose up --no-build<br>Build the images but don’t start the container.<br>&gt;docker-compose build<br>If the images aren’t built beforehand, it fails. The --no-cache option disables the Docker build cache in the image creation process. This is used to cache each layer in the Dockerfile and to speed up the image created by reusing layers (~ Dockerfile lines) previously built for other images that are identical.</p><p>Run a specific compose file<br>&gt;docker-compose -f docker-compose-prod.yml up</p><p>docker-compose build command that will verify changes in Dockerfile and recreate the image in the case when Dockerfile was changed.<br>docker-compose up -d the command will recreate and restart only the container, not the image.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d69e55692e8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Machine Learning Model with backend(flask) and frontend(Angular) -Part3]]></title>
            <link>https://medium.com/@imonbayazid/deploy-machine-learning-model-with-backend-flask-and-frontend-angular-part3-8e3a833ffa92?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e3a833ffa92</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:28:48 GMT</pubDate>
            <atom:updated>2022-04-17T09:28:48.465Z</atom:updated>
            <content:encoded><![CDATA[<p>Now it is time to build the frontend where users can test the real prediction using the machine learning model.<br>The frontend allows the users to provide their information and finally get the prediction.</p><p>we will use angular for making the frontend.<br>First, install node and angular CLI globally on your computer.<br>Then create a simple angular app using angular CLI</p><p>ng new titanic-project<br>cd titanic-projectt<br>ng serve</p><p>Now edit <em>app.component.ts</em> like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0Cvhoa2a4rI6I3xu.png" /></figure><p>It will call the predict method from the backend to get the prediction.<br>An HTTP post-call is used to send input data to the backend and get the prediction.</p><p>We will make a template form where the user can provide their information.<br>Here we used angular <a href="https://ng.ant.design/docs/introduce/en">ant design</a> as the CSS framework.<br>here is our <em>app.component.html</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XGzRUVgBt4CxX_yQ.png" /></figure><p>The final output will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5dSoe1CrK2qJwQN1.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QkM9wDq0JmH9EWNq.png" /></figure><p>We deployed the frontend into Heroku.<br>If you want the code and the structure of the frontend that we deployed, feel free to get it from the<a href="https://github.com/imonbayazid/titanic_data_analysis/tree/frontend"> git repo.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e3a833ffa92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Machine Learning Model with backend(flask) and frontend(Angular) — Part2]]></title>
            <link>https://medium.com/@imonbayazid/deploy-machine-learning-model-with-backend-flask-and-frontend-angular-part2-78ae4eca2502?source=rss-c9499a923db2------2</link>
            <guid isPermaLink="false">https://medium.com/p/78ae4eca2502</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Imon Bayazid]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:27:27 GMT</pubDate>
            <atom:updated>2022-04-17T10:02:20.468Z</atom:updated>
            <content:encoded><![CDATA[<p>Last time, we worked with Jupiter notebook and build our machine learning model.<br>Today, we will make a backend and will use this ML model in our backend.</p><p>We will use a flask for creating our backend.<br>Create a python file named ‘api.py’ which will contain a method for sending the prediction using the ML model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/0*patb7hV-N-dbRkTe.png" /></figure><p>First, create a virtual environment<br>virtualenv myenv<br>Activate virtual environment (for windows)<br>myenv\Scripts\activate<br>Install all required libraries from requirement.txt<br><em>pip install -r requirements.txt</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/0*wqZqLhgEaqo_vSOt.png" /></figure><p>Run the api.py file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/0*fBFQVRSOPr3ZJJjg.png" /></figure><p>We are all set.<br>Check the localhost</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/0*NONIBLCCsELAxrbB.png" /></figure><p>We also deployed the backend at Heroku.<br>If you want the full code and structure which was deployed to the server then check our git only for the backend from <a href="https://github.com/imonbayazid/titanic_data_analysis/tree/backend">here</a>.</p><p>In the next part, we will make our frontend to try out our model and prediction.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78ae4eca2502" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>