<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jayden Nguyen</title>
    <description>The latest articles on DEV Community by Jayden Nguyen (@khanhnhb).</description>
    <link>https://dev.to/khanhnhb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F94717%2F844e8461-4185-41a6-a686-d7c26f01daf5.png</url>
      <title>DEV Community: Jayden Nguyen</title>
      <link>https://dev.to/khanhnhb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khanhnhb"/>
    <language>en</language>
    <item>
      <title>How to install Docker Compose on Ubuntu 18.04</title>
      <dc:creator>Jayden Nguyen</dc:creator>
      <pubDate>Mon, 26 Jul 2021 02:54:08 +0000</pubDate>
      <link>https://dev.to/khanhnhb/how-to-install-docker-compose-on-ubuntu-18-04-288c</link>
      <guid>https://dev.to/khanhnhb/how-to-install-docker-compose-on-ubuntu-18-04-288c</guid>
      <description>&lt;p&gt;Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. read more for detail &lt;a href="https://docs.docker.com/compose/"&gt;Docker Compose Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, I will introduce setup Docker Compose on Ubuntu 18.04 or later version.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Install Docker Compose on Ubuntu Repository
&lt;/h3&gt;

&lt;p&gt;Ubuntu Repository will provide stable version and update for automationally&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then open your terminal and input command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt install docker-compose&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DieVhn2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627194560795/gEtDT9sYi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DieVhn2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627194560795/gEtDT9sYi.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is take few minutes for downloading and installation.&lt;br&gt;
To verify version installation successfully on your system, by command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qCVh5O6p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627194862898/Br2CdproE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qCVh5O6p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627194862898/Br2CdproE.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Install Docker Compose on Ubuntu by GitHub Repository
&lt;/h3&gt;

&lt;p&gt;GitHub is a inventory contain a lot of repository from organization, developer, etc. Contribute to the open source community.&lt;/p&gt;

&lt;p&gt;Install and updated version of Docker utility, copy the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo wget –O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.25.0/docker-compose-Linux-x86_64&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YXHQUmSy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627195379456/dloXW8o9Y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YXHQUmSy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627195379456/dloXW8o9Y.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give the command assign permission to executable file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo chmod +x /usr/local/bin/docker-compose&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--obBtZxJy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627195537355/QlDE94EWE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--obBtZxJy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627195537355/QlDE94EWE.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then permission will be applied to the executable file after this command&lt;br&gt;
To verify version installation successfully on your system, by command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qCVh5O6p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627194862898/Br2CdproE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qCVh5O6p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627194862898/Br2CdproE.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to uninstall Docker Compose on Ubuntu 18.04
&lt;/h3&gt;

&lt;p&gt;The file Docker Compose can be deleted from your system when we remove it is binary&lt;/p&gt;

&lt;p&gt;Given command to remove it:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo rm /usr/local/bin/docker-compose&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. read more for detail &lt;a href="https://docs.docker.com/compose/"&gt;Docker Compose Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📚 Recommended Books&lt;/p&gt;

&lt;p&gt;Clean Code:&lt;a href="https://amzn.to/2UGDPlX"&gt;Book&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTTP: &lt;a href="https://amzn.to/2JDVi8s"&gt;The Definitive Guide &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clean architecture: &lt;a href="https://amzn.to/2xOBNXW"&gt;Book&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📱 Social Media&lt;/p&gt;

&lt;p&gt;Blog: &lt;a href="https://hashnode.com/@KhanhHoang"&gt;KhanhNHB Tech&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twitter: &lt;a href="https://twitter.com/khanh_nhb"&gt;KhanhNHB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Youtube: &lt;a href="https://www.youtube.com/channel/UCp_M_ymiNsbu0_Hs1mIgSZg"&gt;KhanhNHB Tech&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/KhanhNHB"&gt;KhanhNHB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Email: &lt;a href="mailto:khanhnhbse@gmail.com"&gt;khanhnhbse@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>How to build CRUD Spring Boot JPA with MySQL Container on Ubuntu 18.04</title>
      <dc:creator>Jayden Nguyen</dc:creator>
      <pubDate>Mon, 26 Jul 2021 02:42:05 +0000</pubDate>
      <link>https://dev.to/khanhnhb/how-to-build-crud-spring-boot-jpa-with-mysql-container-on-ubuntu-18-04-47d3</link>
      <guid>https://dev.to/khanhnhb/how-to-build-crud-spring-boot-jpa-with-mysql-container-on-ubuntu-18-04-47d3</guid>
      <description>&lt;h2&gt;
  
  
  I. Introduction
&lt;/h2&gt;

&lt;p&gt;In this article you learn about Spring Boot JPA allowing to build simple backend applications by connect MySQL database container by write docker-compose file. Spring Data JPA is a great choice allowing to speed your development and focus on the business logic.&lt;/p&gt;

&lt;p&gt;Technology you can learn in this tutorial:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring Boot JPA&lt;/li&gt;
&lt;li&gt;Build Docker Compose for MySQL&lt;/li&gt;
&lt;li&gt;CRUD operation for simple&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tool support to implementation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IDE Intellij for coding (you can choose other IDE, it is up for you)&lt;/li&gt;
&lt;li&gt;Postman, for manipulate HTTP request&lt;/li&gt;
&lt;li&gt;Docker and Docker Compose, for build MySQL container. You can read more install on Ubuntu 18.04 &lt;a href="https://khanhhoang.hashnode.dev/how-to-install-docker-on-ubuntu-1804"&gt;Install Docker on Ubuntu 18,04&lt;/a&gt;, &lt;a href="https://khanhhoang.hashnode.dev/how-to-install-docker-compose-on-ubuntu-1804"&gt;Install Docker Compose on Ubuntu 18.04&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;GitHub repository at here &lt;a href="https://github.com/KhanhNHB/blog"&gt;blog repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Video reference for coding &lt;a href="https://www.youtube.com/watch?v=NxfbU9YTDQI&amp;amp;t=268s"&gt;at here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  II. Implement
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Initial Project Spring Boot Maven
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In this project I will using Maven. Maven is a build automation tool used for primarily for Java project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open Intellij choose Spring Initializr edit name project, and choose Project SDK, Java version.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Option you can create project on website &lt;a href="https://start.spring.io/"&gt;at here&lt;/a&gt;, click download and extract import project by Intellij.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FI3bXAXn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627209002344/tYvHVtkNl2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FI3bXAXn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627209002344/tYvHVtkNl2.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You can pick add dependency when initial project Spring Data JPA, Spring Web, and MySQL Driver to exploring. or add manual in file pom.xml.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;POM or Project Object Model. It is the fundamental unit of work in Maven. It is a file XML contain information about project and configuration detail used by Maven, read more detail &lt;a href="https://maven.apache.org/guides/introduction/introduction-to-the-pom.html"&gt;at here&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-boot-starter-data-jpa&amp;lt;/artifactId&amp;gt;
        &amp;lt;/dependency&amp;gt;

        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-boot-starter-web&amp;lt;/artifactId&amp;gt;
        &amp;lt;/dependency&amp;gt;

        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;mysql&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;mysql-connector-java&amp;lt;/artifactId&amp;gt;
            &amp;lt;scope&amp;gt;runtime&amp;lt;/scope&amp;gt;
        &amp;lt;/dependency&amp;gt;
 &amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the dependency you can see it is a format XML. It is a naming convention:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;groupId&lt;/strong&gt;: A uniquely identified name of project or organization. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;artifactId&lt;/strong&gt;: A unique name of project. It is mention about packages .&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;version&lt;/strong&gt;: The version of project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;scope&lt;/strong&gt;: Specfic scope for denpendency. There are five scope available:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;compile&lt;/strong&gt;: It is default when none specific scope provided.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;provided&lt;/strong&gt;: The dependencies should be provided at runtime JDK or a container.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;runtime&lt;/strong&gt;: The dependencies with this scope are required at runtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;test&lt;/strong&gt;: Test is aren't transitive and are only present for test and execution classpaths.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;system&lt;/strong&gt;: The scope is similar to the provided scope. The difference is that system requires us to directly point to the specific jar on the system.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 2: Implement &lt;code&gt;docker-compose.file&lt;/code&gt; to start MySQL
&lt;/h4&gt;

&lt;p&gt;Create file &lt;code&gt;docker-compose.file&lt;/code&gt; in root project to run MySQL container.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Docker Compose is tool is defined and running multi-container. It is convention YML file to configuration your application's services. Using Compose a basically a three-step process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Dockerfile to define environment your apps. It can be reproduces anywhere.&lt;/li&gt;
&lt;li&gt;Create docker compose. Define in your app &lt;code&gt;docker-comse.yml&lt;/code&gt;. They can run together in an isolated environment.&lt;/li&gt;
&lt;li&gt;Run docker compose up to start your application's services by command &lt;code&gt;docker-compose up&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: For now I skip Dockerfile. I will create Dockerfile in session later.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3'

services:
  mysql:
    image: mysql:8.0
    container_name: blog_mysql
    volumes:
      - db_mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: blogger
      MYSQL_PASSWORD: blogger
      MYSQL_DATABASE: blog
    ports:
      - 3306:3306

volumes:
  db_mysql:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;version&lt;/strong&gt;: The version of compose. It is number spring format.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;services&lt;/strong&gt;: The make up your application's services.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;mysql&lt;/strong&gt;: The unique name specific service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;image&lt;/strong&gt;: Before colon is the name service you want use, and after colon is version service. Recommend specific version if image will be change in the future.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;container_name&lt;/strong&gt;: The unique name container. It will be generate random if none provided.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;volume&lt;/strong&gt;: It is make persist data. if it finds any containers from previous runs, it copies the volumes from the old container to the new container. This process ensures that any data you’ve created in volumes isn’t lost. Before colon name &lt;code&gt;db_mysql&lt;/code&gt; is a origin folder container script, after colon name is destination &lt;code&gt;/var/lib/mysql&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;environment&lt;/strong&gt;: Is is make permission to access container MySQL to manipulate data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;port&lt;/strong&gt;: The port to access container. Before colon is a port &lt;code&gt;3306&lt;/code&gt; for host machine connect, and after colon the port &lt;code&gt;3306&lt;/code&gt; is MySQL Container.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 3: Configuration &lt;code&gt;application.properties&lt;/code&gt; to connect MySQL
&lt;/h4&gt;

&lt;p&gt;To connect MySQL Container we will be configuration from Spring Boot application at &lt;code&gt;application.properties&lt;/code&gt; in resources folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/blog
spring.datasource.username=blogger
spring.datasource.password=blogger
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;spring.jpa.hibernate.ddl-auto: It can be none, update, create, create-drop see the more detail &lt;a href="https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl"&gt;Hibernate Document&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;none&lt;/strong&gt;: Default MySQL, no change is make database structure. It is good security for the production state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;update&lt;/strong&gt;: The database will be change by Hibernate if the entity given structures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;create&lt;/strong&gt;: Create database every time but does not drop it on close.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;create-drop&lt;/strong&gt;: Create database and drops when &lt;code&gt;SessionFactory&lt;/code&gt; close.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;spring.datasource.url: Given URL connect to MySQL Container for datasource.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;spring.datasource.username: Given username connect to MySQL for datasource.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;spring.datasource.password: Give password connect to MySQL for datasource.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;spring.datasource.driver-class-name: Given name driver MySQL for datasource.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 4: Create &lt;code&gt;@Entity&lt;/code&gt;, Repository, &lt;code&gt;@Controller&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Define Blog class Entity. The Hibernate will be automatically translate entity Blog to table Blog in database.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.khanhnhb.blog.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Blog {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer id;
    public String title;
    public String content;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Entity&lt;/code&gt; annotation this tells Hibernate to make a table out of this class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Define Blog Repository to manipulate interface CRUD records.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.khanhnhb.blog.repository;

import com.khanhnhb.blog.model.Blog;
import org.springframework.data.repository.CrudRepository;

public interface BlogRepository extends CrudRepository&amp;lt;Blog, Integer&amp;gt; {
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; CRUD refers Create, Read, Update, Delete&lt;/li&gt;
&lt;li&gt; Spring automatically implements this repository interface into a beans the same name blogRepository.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Define Blog Controller to using HTTP request.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.khanhnhb.blog.controller;

import com.khanhnhb.blog.model.Blog;
import com.khanhnhb.blog.repository.BlogRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping(path = "/blogs")
public class BlogController {

    @Autowired
    private BlogRepository blogRepository;

    @PostMapping()
    public @ResponseBody Blog createBlog(@RequestBody Blog newBlog) {
        return blogRepository.save(newBlog);
    }

    @GetMapping()
    public @ResponseBody Iterable&amp;lt;Blog&amp;gt; getAll() {
        return blogRepository.findAll();
    }

    @GetMapping(path = "{id}")
    public @ResponseBody Blog getOne(@PathVariable Integer id) {
        return blogRepository.findById(id).get();
    }

    @PutMapping(path = "{id}")
    public @ResponseBody Blog updateBlog(@PathVariable Integer id, @RequestBody Blog updateBlog) {
        Blog blog = blogRepository.findById(id).get();

        blog.setTitle(updateBlog.getTitle());
        blog.setContent(updateBlog.getContent());

        return blogRepository.save(blog);

    }

    @DeleteMapping(path = "{id}")
    public @ResponseBody Integer deleteBlog(@PathVariable Integer id) {
        Blog blog = blogRepository.findById(id).get();
        blogRepository.delete(blog);
        return blog.getId();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Controller&lt;/code&gt; annotation it means that this class is a Controller.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@RequestMapping&lt;/code&gt; annotation it means URL's start with /blog (after Application path)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@Autowire&lt;/code&gt; annotation its means to get the bean called blogRepository. Which is auto-generated by Spring when application start, we will use it to handle the data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@PostMapping&lt;/code&gt; annotations its mean map ONLY POST Requests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@RequestBody&lt;/code&gt; annotations its mean pass value in body request.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@ResponseBody&lt;/code&gt; annotations its mean returned object data type (Blog, Integer, ...).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@GetMapping&lt;/code&gt; annotations its mean map ONLY GET Requests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@PathVariable&lt;/code&gt; annotations its mean can be use handle template variables in the request URL.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@PutMapping&lt;/code&gt; annotations its mean map ONLY PUT Requests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@DeleteMapping&lt;/code&gt; annotations its mean map ONLY DELETE Requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 5: Make HTTP request with Postman
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Create Blog&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;POST: localhost:8080/blogs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body: 
{
    "title": "Exploring Spring Data JPA",
    "content: "Create first blog"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TpfSN7ok--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213365569/LK1em-KbL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TpfSN7ok--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213365569/LK1em-KbL.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read all Blog&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GET: localhost:8080/blogs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--engHSyLb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213406036/1k85OvMBt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--engHSyLb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213406036/1k85OvMBt.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read blog by id&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GET: localhost:8080/blogs/1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iZRaaix5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213799356/_ZWXeo-b3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iZRaaix5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213799356/_ZWXeo-b3.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update blog&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;PUT: localhost:8080/blogs/1&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body: 
{
    "title": "Exploring Spring Data JPA and MySQL",
    "content: "Modify first blog"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l3PddIwb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213705019/hc4XbiEaAt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l3PddIwb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213705019/hc4XbiEaAt.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delete blog&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;DELETE: localhost:8080/blogs/1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1hKb2pS0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213889632/3tH7u00PU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1hKb2pS0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1627213889632/3tH7u00PU.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  III. Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article you learn about Spring Boot JPA allowing to build simple backend applications by connect MySQL database container by write docker-compose file.&lt;/p&gt;

&lt;p&gt;📚 Recommended Books&lt;/p&gt;

&lt;p&gt;Clean Code:&lt;a href="https://amzn.to/2UGDPlX"&gt;Book&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTTP: &lt;a href="https://amzn.to/2JDVi8s"&gt;The Definitive Guide &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clean architecture: &lt;a href="https://amzn.to/2xOBNXW"&gt;Book&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📱 Social Media&lt;/p&gt;

&lt;p&gt;Blog: &lt;a href="https://hashnode.com/@KhanhHoang"&gt;KhanhNHB Tech&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twitter: &lt;a href="https://twitter.com/khanh_nhb"&gt;KhanhNHB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Youtube: &lt;a href="https://www.youtube.com/channel/UCp_M_ymiNsbu0_Hs1mIgSZg"&gt;KhanhNHB Tech&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/KhanhNHB"&gt;KhanhNHB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Youtube: KhanhNHB Tech&lt;/p&gt;

&lt;p&gt;GitHub: KhanhNHB&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to run image Elasticsearch Container on Ubuntu 18.04</title>
      <dc:creator>Jayden Nguyen</dc:creator>
      <pubDate>Fri, 16 Jul 2021 15:33:44 +0000</pubDate>
      <link>https://dev.to/khanhnhb/how-to-run-image-elasticsearch-container-on-ubuntu-18-04-2lc8</link>
      <guid>https://dev.to/khanhnhb/how-to-run-image-elasticsearch-container-on-ubuntu-18-04-2lc8</guid>
      <description>&lt;p&gt;Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents. To read more about at &lt;a href="https://www.elastic.co/"&gt;Elasticsearch Document&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this post I will introduction setup about Elasticsearch container on Ubuntu 18.04. It is make sure you already install docker please check more content at &lt;a href="https://www.notion.so/How-to-install-Docker-on-Ubuntu-18-04-1f899e145c984b899495a5fe1f33560d"&gt;Install Docker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are have 3 steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Downloading &lt;a href="https://hub.docker.com/_/elasticsearch"&gt;image Elasticsearch&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Pull Image Elasticsearch on Docker Hub by command:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;docker pull elasticsearch:tag&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tag is a specific version image. Recommended specific for version if image have any change version in the future&lt;/p&gt;

&lt;p&gt;Verify pull image success by command:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;docker images&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Running in Development Mode for start container&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:tag&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Some describes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;-d: It is detach running container in background&lt;/li&gt;
&lt;li&gt;--name: The name of container&lt;/li&gt;
&lt;li&gt;-p: Port container will expose to host&lt;/li&gt;
&lt;li&gt;-e: It is environment for container&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Verify running container success&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The command just shows running containers&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;docker ps&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To see all containers, use flag -a&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;docker ps -a&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Open browser access localhost:9200&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Stop running container and remove container&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can stop container by id or by name&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;docker stop container_id&lt;/p&gt;

&lt;p&gt;docker stop container_name&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Verify stop container by command&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;docker ps -a&lt;/p&gt;

&lt;p&gt;docker ps&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this post I have implemented setup Elasticsearch by pull image, run, stop and remove container on Ubuntu 18.04. To learn more about &lt;a href="https://docs.docker.com/"&gt;Docker Document&lt;/a&gt;, and &lt;a href="https://www.elastic.co/"&gt;Elastichsearch Document&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you have any question please comment or contact me.&lt;/p&gt;

&lt;p&gt;Author: @NHB Khanh&lt;/p&gt;

&lt;p&gt;📚 Recommended Books&lt;/p&gt;

&lt;p&gt;Clean Code:&lt;a href="https://amzn.to/2UGDPlX"&gt;Book&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTTP: &lt;a href="https://amzn.to/2JDVi8s"&gt;The Definitive Guide &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clean architecture: &lt;a href="https://amzn.to/2xOBNXW"&gt;Book&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📱 Social Media&lt;/p&gt;

&lt;p&gt;Blog: &lt;a href="https://hashnode.com/@KhanhHoang"&gt;KhanhNHB Tech&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twitter: &lt;a href="https://twitter.com/khanh_nhb"&gt;KhanhNHB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Email: &lt;a href="//mailto:khanhnhbse@gmail.com"&gt;khanhnhbse@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>elasticsearch</category>
      <category>docker</category>
    </item>
    <item>
      <title>How to install Docker on Ubuntu 18.04</title>
      <dc:creator>Jayden Nguyen</dc:creator>
      <pubDate>Fri, 16 Jul 2021 14:35:30 +0000</pubDate>
      <link>https://dev.to/khanhnhb/how-to-install-docker-on-ubuntu-18-04-container-1eb1</link>
      <guid>https://dev.to/khanhnhb/how-to-install-docker-on-ubuntu-18-04-container-1eb1</guid>
      <description>&lt;p&gt;Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. You can references to documents at this &lt;a href="https://www.docker.com/"&gt;https://www.docker.com/&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Need to update software repositories. Run the following command:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo apt-get update&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 2:  Install Docker on Ubuntu 18.04&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To install latest version you can run command&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo apt install docker-ce docker-ce-cli &lt;a href="http://containerd.io/"&gt;containerd.io&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To install specific version docker&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;apt list -a docker-ce&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then install specific version&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo apt install docker-ce= docker-ce-cli= &lt;a href="http://containerd.io/"&gt;containerd.io&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can verify Docker service after install. It is start automation when install completed&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo systemctl status docker&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Execute docker on-non root user&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo usermod -aG docker $USER&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally, you can make verify docker is install success&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;docker run hello-world&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Uninstall docker&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;To stop all running containers and Docker instance&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;docker container stop $(docker container ls -aq)&lt;/p&gt;

&lt;p&gt;docker system prune -a --volumes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now uninstall Docker as any other package installed with apt&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo apt purge docker-ce&lt;/p&gt;

&lt;p&gt;sudo apt autoremove&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In this post I will introduction way to install docker on Ubuntu 18.04. To learn more about Docker you, check out official &lt;a href="https://docs.docker.com/"&gt;Docker Offical Document&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have any question please comment or contact me.&lt;/p&gt;

&lt;p&gt;Author: @NHB Khanh &lt;/p&gt;

&lt;p&gt;Facebook: &lt;a href="https://www.facebook.com/pi.ke.1044/"&gt;facebook.com/khanhnhb&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Email: &lt;a href="mailto:khanhnhbse@gmail.com"&gt;khanhnhbse@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
