<?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: Mohamed Kramti</title>
    <description>The latest articles on DEV Community by Mohamed Kramti (@mohamed_kramti).</description>
    <link>https://dev.to/mohamed_kramti</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%2F2141487%2Fb81fa14c-b051-46ab-8730-fe527bae2f61.jpg</url>
      <title>DEV Community: Mohamed Kramti</title>
      <link>https://dev.to/mohamed_kramti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohamed_kramti"/>
    <language>en</language>
    <item>
      <title>Getting Started with Maven</title>
      <dc:creator>Mohamed Kramti</dc:creator>
      <pubDate>Fri, 18 Oct 2024 19:43:08 +0000</pubDate>
      <link>https://dev.to/mohamed_kramti/getting-started-with-maven-5e04</link>
      <guid>https://dev.to/mohamed_kramti/getting-started-with-maven-5e04</guid>
      <description>&lt;p&gt;Read full post  at &lt;a href="https://kramti.com/post/getting-started-with-maven" rel="noopener noreferrer"&gt;Getting Started with Maven&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;If you're a Java developer, you've likely used Maven to build and manage your projects.&lt;/p&gt;

&lt;p&gt;In this post, you'll learn the basics of using Maven in your projects.&lt;/p&gt;

&lt;h1&gt;
  
  
  Understanding Maven's Project Structure
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;my-maven-project/pom.xml&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Defines the Maven project. It includes a unique identifier for the project, properties, dependencies, and necessary modules.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;my-maven-project/src/main/java&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Contains the source code of the project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;my-maven-project/src/main/resources&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Contains resource files (like application.properties).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;my-maven-project/src/test&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Contains the test code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;my-maven-project/src/it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Contains integration tests.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;my-maven-project/target&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Contains compiled classes, JAR/WAR files, and other artifacts.&lt;/p&gt;

&lt;h1&gt;
  
  
  POM File
&lt;/h1&gt;

&lt;p&gt;Key Elements&lt;/p&gt;

&lt;p&gt;The pom.xml file holds crucial information about the project. Each project must have a unique identifier, specified by:&lt;/p&gt;

&lt;p&gt;groupId (usually your domain name)&lt;br&gt;
artifactId (usually the project name)&lt;br&gt;
version (project version)&lt;/p&gt;

&lt;p&gt;Additionally, the pom.xml can include the project's name, description, and packaging type (e.g., JAR/WAR).&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;groupId&amp;gt;com.kramti&amp;lt;/groupId&amp;gt;

&amp;lt;artifactId&amp;gt;example&amp;lt;/artifactId&amp;gt;

&amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt;

&amp;lt;name&amp;gt;My Maven Example&amp;lt;/name&amp;gt;

&amp;lt;description&amp;gt;This is a Maven pom.xml example&amp;lt;/description&amp;gt;

&amp;lt;packaging&amp;gt;war&amp;lt;/packaging&amp;gt;

&amp;lt;properties&amp;gt;

&amp;lt;java.version&amp;gt;21&amp;lt;/java.version&amp;gt;

&amp;lt;/properties&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Dependencies
&lt;/h2&gt;

&lt;p&gt;Dependencies are external libraries your project requires. Instead of manually downloading and importing JAR files, Maven simplifies this by managing dependencies within the pom.xml.&lt;/p&gt;

&lt;p&gt;To add a dependency, you need its groupId, artifactId, version (optional), and scope (optional). You can find dependencies on the Maven Repository.&lt;/p&gt;

&lt;p&gt;Example of a dependency:&lt;br&gt;
&lt;/p&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;version&amp;gt;&amp;lt;/version&amp;gt;

&amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, if you need a dependency only for testing purposes, use the scope tag:&lt;br&gt;
&lt;/p&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-test&amp;lt;/artifactId&amp;gt;

&amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;

&amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Maven Build Lifecycle
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;validate: Checks if the project is correct and all necessary information is available.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;compile: Compiles the project's source code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;test: Runs unit tests using a suitable testing framework.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;package: Packages the compiled code into a distributable format (e.g., JAR or WAR).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;install: Installs the package into the local repository for use by other projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;deploy: Deploys the built package to a remote repository for sharing with other developers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Maven Plugins
&lt;/h1&gt;

&lt;p&gt;Using Maven Plugins Maven plugins are essential for customizing the build process. You can use plugins for tasks such as compiling code, running tests, and generating reports. &lt;/p&gt;

&lt;p&gt;Example of a compiler plugin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;plugin&amp;gt;

&amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;

&amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;

&amp;lt;version&amp;gt;3.8.1&amp;lt;/version&amp;gt;

&amp;lt;configuration&amp;gt;

&amp;lt;source&amp;gt;1.8&amp;lt;/source&amp;gt;

&amp;lt;target&amp;gt;1.8&amp;lt;/target&amp;gt;

&amp;lt;/configuration&amp;gt;

&amp;lt;/plugin&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Popular plugins include:&lt;/p&gt;

&lt;p&gt;maven-compiler-plugin: Compiles Java source code.&lt;/p&gt;

&lt;p&gt;maven-surefire-plugin: Runs unit tests.&lt;/p&gt;

&lt;p&gt;maven-jar-plugin: Packages the project into a JAR file.&lt;/p&gt;

&lt;h1&gt;
  
  
  Best Practices for Maven Projects
&lt;/h1&gt;

&lt;p&gt;Keep Dependencies Up-to-Date: Regularly update your dependencies to avoid vulnerabilities.&lt;/p&gt;

&lt;p&gt;Avoid Version Conflicts: Use the  section in the parent POM to manage dependency versions in multi-module projects.&lt;/p&gt;

&lt;p&gt;Minimize Plugin Configuration: Keep plugin configurations minimal and only configure what’s necessary for your project.&lt;/p&gt;

&lt;p&gt;Build performance: For large projects, Maven builds can be slow. Use the -T option to enable parallel builds&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Maven is an essential tool for Java developers. It simplifies project management by automating builds, handling dependencies and plugins. Understanding its structure, POM file, and core features allows for more efficient and organized workflows.&lt;/p&gt;

&lt;h1&gt;
  
  
  You may be interested in
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://kramti.com/post/java-performance-optimization-techniques" rel="noopener noreferrer"&gt;Java Performance Optimization Techniques&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kramti.com/post/docker-in-nutshell" rel="noopener noreferrer"&gt;Docker in nutshell&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kramti.com/post/transactions-in-spring-boot" rel="noopener noreferrer"&gt;Transactions in Spring boot&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>spring</category>
      <category>maven</category>
    </item>
    <item>
      <title>Java Performance Optimization Techniques</title>
      <dc:creator>Mohamed Kramti</dc:creator>
      <pubDate>Thu, 03 Oct 2024 19:44:03 +0000</pubDate>
      <link>https://dev.to/mohamed_kramti/java-performance-optimization-techniques-45d1</link>
      <guid>https://dev.to/mohamed_kramti/java-performance-optimization-techniques-45d1</guid>
      <description>&lt;p&gt;Hello 👋&lt;br&gt;
You can find the full post on &lt;a href="https://kramti.com/#/post/java-performance-optimization-techniques" rel="noopener noreferrer"&gt;Java Performance Optimization Techniques&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Overview
&lt;/h1&gt;

&lt;p&gt;Optimizing your code performance is critical for the success of your profile. Did you know that Akamai's research found that 57% of online consumers abandon a website if a page takes longer than 3 seconds to load? In this post, you will learn how to optimize your Java code and improve your code performance.&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Virtual Threads
&lt;/h1&gt;

&lt;p&gt;Say no more to OutOfMemoryError: unable to create new native thread Error.&lt;/p&gt;

&lt;p&gt;Java virtual threads, introduced in Java 19, can significantly improve the performance of your project.&lt;/p&gt;

&lt;p&gt;In the previous releases of Java, there was only 1 type of thread (Classic threads) when a classic thread is created an OS thread is allocated and the number of threads is limited to the OS threads.&lt;/p&gt;

&lt;p&gt;Starting from JDK 19, you can create virtual threads which are much lighter than OS threads and you can create and run thousands of virtual threads in an application.&lt;/p&gt;

&lt;p&gt;To enable virtual threads in a Spring Boot application add the following code to your application.properties.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;spring.threads.virtual.enabled=true&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Lazy loading
&lt;/h1&gt;

&lt;p&gt;A lot of performance problems arise from fetching data that you don't need.&lt;/p&gt;

&lt;p&gt;It's best practice to only load objects when needed.&lt;/p&gt;

&lt;p&gt;For instance, you can use FetchLazy in Hibernate but always keep in mind that the appropriate fetch strategy depends on the specific use case you're dealing with.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fetch = FetchType.LAZY&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Cache
&lt;/h1&gt;

&lt;p&gt;Minimize disk access by caching frequently accessed data. By using proper caching techniques you can reduce latency, avoid network congestion and improve content availability.&lt;/p&gt;

&lt;p&gt;The Spring framework provides support for various cache providers including but not limited to Redis, Caffeie, Cache2k etc...&lt;/p&gt;

&lt;h1&gt;
  
  
  5. Avoid GenerationType.TABLE
&lt;/h1&gt;

&lt;p&gt;When choosing a key generation strategy in JPA, it's important to select the one that best fits the database you're using.&lt;br&gt;
GenerationType.TABLE&lt;/p&gt;

&lt;p&gt;Avoid using GenerationType.TABLE for its performance overhead. Each time a primary key is needed a LOCK statement is executed, along with a select and update on the sequence table.&lt;br&gt;
GenerationType.IDENTITY&lt;/p&gt;

&lt;p&gt;GenerationType.IDENTITY is best suited for MySQL because MySQL uses auto-increment fields and GenerationType.IDENTITY works well with this.&lt;br&gt;
GenerationType.SEQUENCE&lt;/p&gt;

&lt;p&gt;GenerationType.SEQUENCE is typically used with PostgreSQL and Oracle. Both databases support sequences, which are database objects that generate a sequence of unique numbers.&lt;/p&gt;

&lt;h1&gt;
  
  
  6. Query Plan Cache
&lt;/h1&gt;

&lt;p&gt;Hibernate's Query Plan Cache is a key feature that can improve the performance of your application.&lt;/p&gt;

&lt;p&gt;When hibernate executes a JPQL query, the corresponding SQL query needs to be generated. This process involves parsing the query to an Abstract Syntax Tree, translating the tree to an SQL query and finally mapping the result back to Java objects.&lt;/p&gt;

&lt;p&gt;Once this process is complete, hibernate caches the process so that it doesn't need to perform these steps again for the same query.&lt;/p&gt;

&lt;p&gt;To enable and configure the Query Plan cache use the following code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;hibernate.query.plan_cache_max_size=2048 # Maximum number of query plans in the cache &lt;br&gt;
hibernate.query.plan_parameter_metadata_max_size=128 # Max size of query plans with parameter metadata&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  7. Conclusion
&lt;/h1&gt;

&lt;p&gt;Optimizing Java code performance is essential for delivering fast and responsive applications.&lt;/p&gt;

&lt;p&gt;By leveraging modern features like virtual threads, implementing lazy loading, using efficient caching strategies, and optimizing your database operations, you can significantly improve your application's performance.&lt;/p&gt;

&lt;h1&gt;
  
  
  You may be interested in
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://kramti.com/post/getting-started-with-maven" rel="noopener noreferrer"&gt;Getting Started with Maven&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kramti.com/post/docker-in-nutshell" rel="noopener noreferrer"&gt;Docker in nutshell&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kramti.com/post/transactions-in-spring-boot" rel="noopener noreferrer"&gt;Transactions in Spring boot&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>java</category>
      <category>spring</category>
      <category>springboot</category>
    </item>
    <item>
      <title>Docker In Nutshell + Docker Cheat Sheet</title>
      <dc:creator>Mohamed Kramti</dc:creator>
      <pubDate>Sun, 29 Sep 2024 10:12:31 +0000</pubDate>
      <link>https://dev.to/mohamed_kramti/docker-in-nutshell-docker-cheat-sheet-k2a</link>
      <guid>https://dev.to/mohamed_kramti/docker-in-nutshell-docker-cheat-sheet-k2a</guid>
      <description>&lt;h1&gt;
  
  
  Note from the author
&lt;/h1&gt;

&lt;p&gt;Hello 👋&lt;/p&gt;

&lt;p&gt;This is my first post on dev.to&lt;/p&gt;

&lt;p&gt;If you like my post, please like it and let’s connect on &lt;a href="https://www.linkedin.com/in/medkramti/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check out my blog at &lt;a href="https://kramti.com" rel="noopener noreferrer"&gt;https://kramti.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scroll to the end of the post for an amazing Docker Cheat Sheet &lt;a href="https://kramti.com/#/post/docker-in-nutshell" rel="noopener noreferrer"&gt;Docker In Nutshell + Docker Cheat Sheet&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;This article covers everything you need to know to start using Docker.&lt;/p&gt;

&lt;p&gt;I will begin by presenting Docker and the issues it solves, then I’ll clarify the most used terms related to Docker, and finally, we will dockerize an application and run our first container.&lt;/p&gt;

&lt;h1&gt;
  
  
  What Problem Does Docker Solve?
&lt;/h1&gt;

&lt;p&gt;1) Settings up an environment can be complex for some people, especially for a less technical person.&lt;/p&gt;

&lt;p&gt;Docker will install all the dependencies your application need; You don’t have to worry about setting up your MySQL, installing Java, node or any other tool.&lt;/p&gt;

&lt;p&gt;2) If you don’t want to share the filesystem, database, network interface, port or OS … between applications docker got you covered thanks to its isolation technique.&lt;/p&gt;

&lt;p&gt;3) Security - Isolation concerns security too, deploying a vulnerable application or a malicious code can damage the other applications, and that's why it’s better to keep apps isolated.&lt;/p&gt;

&lt;p&gt;4) Portability - As long as the Docker versions are compatible your shipped software will work anywhere&lt;/p&gt;

&lt;h1&gt;
  
  
  Key terms
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Docker
&lt;/h2&gt;

&lt;p&gt;Docker is an open-source project that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Will help you deploy your applications.&lt;/li&gt;
&lt;li&gt;Packages your applications into an image that can be used anywhere.&lt;/li&gt;
&lt;li&gt;Uses &lt;em&gt;containers&lt;/em&gt; to run applications in isolated environments&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Images
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Images contain:

&lt;ul&gt;
&lt;li&gt;Application code&lt;/li&gt;
&lt;li&gt;Dependencies&lt;/li&gt;
&lt;li&gt;Configuration&lt;/li&gt;
&lt;li&gt;Runtime environment&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; Images are read-only you can’t change the content of an image; if you need to change the content of an image you have to create a new image with the changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Containers
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A container:

&lt;ul&gt;
&lt;li&gt;Is a runnable instance of an image.&lt;/li&gt;
&lt;li&gt;Completely Isolated process (runs undependably from any process on your computer).&lt;/li&gt;
&lt;li&gt;Help to improve the deployment of an application.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Note: We can create multiple containers from the same image.&lt;/p&gt;

&lt;h1&gt;
  
  
  Install Docker
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Install Docker on Windows
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install WSL
&lt;/h3&gt;

&lt;p&gt;WSL stands for Windows Subsystem for Linux.&lt;/p&gt;

&lt;p&gt;It’s a feature in Windows 10 version 2004+ and windows 11; it allows Linux programs to run on Windows&lt;/p&gt;

&lt;p&gt;To install WSL simply run this command on PowerShell&lt;/p&gt;

&lt;p&gt;&lt;code&gt;wsl --install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Alternatively, if you want to install it manually follow this guide&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/windows/wsl/install-manual" rel="noopener noreferrer"&gt;Manual installation steps for older versions of WSL | Microsoft Learn&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Docker Desktop
&lt;/h3&gt;

&lt;p&gt;The next step is to install the Docker Desktop&lt;/p&gt;

&lt;p&gt;You can follow this link to download the Docker Desktop&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.docker.com/desktop/install/windows-install/" rel="noopener noreferrer"&gt;Install Docker Desktop on Windows | Docker Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The installation is really simple we won’t go into in this tutorial&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Docker on Ubuntu
&lt;/h2&gt;

&lt;p&gt;Before installing docker on your Linux system you must install some dependencies that Docker needs&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt-get install ca-certificates curl gnupg lsb-release&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the Docker GPG key&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo mkdir -p /etc/apt/keyrings&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Set up the repository&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list &amp;gt; /dev/null&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And lastly, install Docker&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Docker on other platforms
&lt;/h2&gt;

&lt;p&gt;Docker supports a variety of platforms (Linux platforms, macOS and Windows). For more details check the official documentation &lt;a href="https://docs.docker.com/engine/install/" rel="noopener noreferrer"&gt;Install Docker Engine | Docker Documentation&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the installation
&lt;/h2&gt;

&lt;p&gt;After installing docker you can run your first container using this command&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hello from Docker!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This message shows that your installation appears to be working correctly.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;…&lt;/p&gt;

&lt;p&gt;If you see this message, then congratulation you have successfully installed Docker.&lt;/p&gt;

&lt;h1&gt;
  
  
  DockerHub
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is DockerHub?
&lt;/h2&gt;

&lt;p&gt;Docker Hub is a service provided by Docker to download and share docker images.&lt;/p&gt;

&lt;p&gt;You can access DockerHub from this link &lt;a href="https://hub.docker.com/" rel="noopener noreferrer"&gt;Docker Hub Container Image Library | App Containerization&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Download an image from DockerHub
&lt;/h2&gt;

&lt;p&gt;Let’s say you need a Linux OS to deploy your application&lt;/p&gt;

&lt;p&gt;1- Go to &lt;a href="http://hub.docker.com" rel="noopener noreferrer"&gt;hub.docker.com&lt;/a&gt; and search for the OS you need to install I’ll take Ubuntu as an example&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F33f0a41c-1ccb-4f8f-9ea6-21885c7a1300%2F02_-_hub_ubuntu_search.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F33f0a41c-1ccb-4f8f-9ea6-21885c7a1300%2F02_-_hub_ubuntu_search.png" alt="02 - hub ubuntu search.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- You will get a variety of images, select the image you need to install in my case the official Ubuntu image&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F03bd9311-643e-4eac-a942-f5beff68d592%2F03_-_hub_ubuntu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F03bd9311-643e-4eac-a942-f5beff68d592%2F03_-_hub_ubuntu.png" alt="03 - hub ubuntu.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Run the &lt;strong&gt;docker pull ubuntu&lt;/strong&gt; command on your terminal, CMD or PowerShell.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;…&lt;/p&gt;

&lt;p&gt;Status: Downloaded newer image for ubuntu: latest&lt;br&gt;
&lt;a href="http://docker.io/library/ubuntu:latest" rel="noopener noreferrer"&gt;docker.io/library/ubuntu:latest&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulation now you have downloaded your first image, you may have noticed that the image size is way smaller than the official ubuntu Iso image and that’s another advantage of docker.&lt;/p&gt;

&lt;p&gt;Note: By default, &lt;strong&gt;docker pull ubuntu&lt;/strong&gt; will pull the latest version, but you can specify the docker version following the image name example &lt;strong&gt;docker pull ubuntu:20.04&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Note: Alternatively, if you don’t want to go to &lt;a href="http://hub.docker.com" rel="noopener noreferrer"&gt;hub.docker.com&lt;/a&gt; and search for the image using your browser you can search for images using your command line simply type &lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker search ubuntu&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;This command will list all the available images, their descriptions and more …&lt;/p&gt;

&lt;h1&gt;
  
  
  DockerFile
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is a DockerFile?
&lt;/h2&gt;

&lt;p&gt;A DockerFile is a file that contains a set of instructions for docker to create your own image, for example, it may contain the OS your application will run on, the source code of your application etc… &lt;/p&gt;

&lt;p&gt;A DockerFile does not have an extension and it contains a set of instructions&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create a DockerFile?
&lt;/h2&gt;

&lt;p&gt;We learned previously that a DockerFile is a set of instructions below are the most common instructions used on DockerFiles&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FROM&lt;/strong&gt; is used to define the parent image that the new image will be built.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;COPY &amp;amp; ADD&lt;/strong&gt; is used to copy files to the filesystem of the image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WORKDIR&lt;/strong&gt; is used to specify the working directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RUN&lt;/strong&gt; is used to run commands to run inside the container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CMD&lt;/strong&gt; is used to specify a command that executes by default when running a Docker container.&lt;/p&gt;

&lt;p&gt;For more DockerFile instructions visit &lt;a href="https://docs.docker.com/engine/reference/builder/" rel="noopener noreferrer"&gt;Dockerfile reference | Docker Documentation&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Dockerizing a Node.js web app
&lt;/h3&gt;

&lt;p&gt;Note: Optional you can install a Docker extension in your editor.&lt;/p&gt;

&lt;p&gt;Step 1 - Define the parent container&lt;/p&gt;

&lt;p&gt;&lt;code&gt;FROM node:16&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step 2 - Define the working directory which will contain our node application&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WORKDIR /usr/src/app&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note:  The following instructions will be executed inside /usr/src/app&lt;/p&gt;

&lt;p&gt;Step 3 - Copy the node application to our image&lt;/p&gt;

&lt;p&gt;&lt;code&gt;COPY . .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: The first dot represents the current file on our host machine, and the second dot is the current working directory.&lt;/p&gt;

&lt;p&gt;Step 4 - Informing Docker of the port our application is listening to&lt;/p&gt;

&lt;p&gt;&lt;code&gt;EXPOSE 4444&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step 5 - Installing the application dependencies &lt;/p&gt;

&lt;p&gt;&lt;code&gt;RUN npm install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step 6 - Lastly define the command to run the application&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CMD [ "node", "server.js" ]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That’s all! The DockerFile should look like that&lt;/p&gt;

&lt;p&gt;&lt;code&gt;FROM node:16&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WORKDIR /usr/src/app&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;COPY . .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;EXPOSE 4444&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RUN npm install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CMD [ "node", "server.js" ]&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  DockerIgnore file
&lt;/h3&gt;

&lt;p&gt;The .dockerIgnore file is similar to the .gitignore you simply include the path to the files or folders you want Docker to ignore while dockerizing your application.&lt;/p&gt;

&lt;p&gt;In the previous example, we can create a .dockerignore file to ignore the node_modules folder&lt;/p&gt;

&lt;p&gt;Simply create a .dockerignore file and it should contain one line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node_modules&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Build the Image
&lt;/h2&gt;

&lt;p&gt;Now that we had set up the DockerFile and the .dockerIgnore file we can build our image&lt;/p&gt;

&lt;p&gt;to do so simply run the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t [ Type your image tag here ]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t myFirstImage&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Start &amp;amp; Stop the Container
&lt;/h1&gt;

&lt;p&gt;To start the image created you can use the Docker Desktop application just go to images ⇒ select the image and click run&lt;/p&gt;

&lt;p&gt;or we can use the command line&lt;/p&gt;

&lt;p&gt;This command displays all the available images&lt;/p&gt;

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

&lt;p&gt;and to start the container&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -p 8080:4444 --name [Give the container a name] [Image name]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -p 8080:4444 --name myContainer myFirstImage&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;code&gt;-p 8080:4444&lt;/code&gt;is used to map the 8080 port to the exposed port 4444.&lt;/p&gt;

&lt;p&gt;We will be able to access the exposed port using the 8080 port on the local host.&lt;/p&gt;

&lt;p&gt;To see the running container run&lt;/p&gt;

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

&lt;p&gt;This command displays the running containers along with their ID, created date, and Ports&lt;/p&gt;

&lt;p&gt;To stop the container run&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker stop [Container id or Container name]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker stop myContainer&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this article you learned pretty much everything you need to get started with Docker from basic concepts, downloading and installing Docker to creating and managing your Docker images and container.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>web</category>
      <category>webdev</category>
      <category>containers</category>
    </item>
  </channel>
</rss>
