<?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 sachinda nipun on Medium]]></title>
        <description><![CDATA[Stories by sachinda nipun on Medium]]></description>
        <link>https://medium.com/@sachindanipun96?source=rss-89cccac1ccc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FODVA9B9SBgxc9US</url>
            <title>Stories by sachinda nipun on Medium</title>
            <link>https://medium.com/@sachindanipun96?source=rss-89cccac1ccc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 06:32:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sachindanipun96/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[Machine Learning from Scratch, Part 1: What ML Is and Understanding X and Y]]></title>
            <link>https://medium.com/@sachindanipun96/machine-learning-from-scratch-part-1-what-ml-is-and-understanding-x-and-y-3eeba5d4adb6?source=rss-89cccac1ccc------2</link>
            <guid isPermaLink="false">https://medium.com/p/3eeba5d4adb6</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[mls]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[sachinda nipun]]></dc:creator>
            <pubDate>Sun, 01 Nov 2026 08:18:37 GMT</pubDate>
            <atom:updated>2026-11-01T08:18:37.232Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is ML?</strong></p><p>When we hear the question “What is ML?”, it feels tricky to explain, and it’s hard to know where to start. I felt the same at first, but after reading and studying ML, I realised the basic idea is quite simple. Let’s understand it with an example.</p><p>Imagine we own a shop and want to predict which products will sell best in the future. We have several years of sales records. In normal programming, we would have to write the rules ourselves, for example “if a product’s sales grew three months in a row, it will keep selling well.” But real buying behaviour depends on many things at once, such as season, price, holidays, and trends. Writing all those rules by hand is almost impossible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fuPtuG32x4c6JeChgZUthg.jpeg" /></figure><p>So we do it differently. We give the computer the past sales data and let it find the patterns by itself. This step is called <strong>training</strong>, and the result is a <strong>model</strong>: the set of rules the machine learned. Then we give the model new information, such as next month’s dates and prices, and it <strong>predicts</strong> which products will sell best.</p><p>But before we hand any data to a model, there’s one more thing we really need to understand. Every dataset has two parts: the <strong>features</strong> and the <strong>dependent variable</strong>. To keep it simple, I’ll call the features <strong>X</strong> and the dependent variable <strong>Y</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0GRwcqt1ylg3Vt4jpPuXw.jpeg" /></figure><p><strong>Dependent variable (Y)</strong></p><p>Let’s start with Y, because honestly, this is where everything begins. Y is simply the result we want the model to predict. In our shop example, that’s how many units of each product we’ll sell next month. Once we have that number, finding the best sellers is easy: they’re just the products with the highest predictions.</p><p>When I started learning, I thought Y was a small detail. It’s not. If you’re not clear about what you want to predict, you can’t choose the right data, and you can’t choose the right kind of model either.</p><p><strong>Features (X)</strong></p><p>Features are the information we give the model so it can make that prediction. If we look at our shop records again, we have things like the product’s price, the month, whether there was a discount, and how many units sold last month. All of these could affect next month’s sales, so they’re good candidates for X.</p><p>But here’s the tricky part: more data isn’t always better. Our records might also include things like the cashier’s name or the receipt number. Those have nothing to do with how well a product sells, and if we feed them to the model, they can actually make the predictions worse. So we have to think carefully about which data really matters and filter out the rest. We’ll talk about this properly in the data preprocessing section.</p><p>One mistake I want to point out, because I almost made it myself: don’t put the answer inside your features. For example, “units sold next month” is our Y, so it must never be part of X. Using “units sold last month” is fine, though, because that’s information we actually have at the moment of prediction.</p><p>Now that we know what X and Y are, there’s one more decision before preprocessing: what type of machine learning problem are we solving? This matters a lot, because choosing the right type helps us pick the right model and get the best results. Let’s look at that next.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3eeba5d4adb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Virtual Threads in Java]]></title>
            <link>https://medium.com/@sachindanipun96/virtual-threads-in-java-8609a4babef2?source=rss-89cccac1ccc------2</link>
            <guid isPermaLink="false">https://medium.com/p/8609a4babef2</guid>
            <category><![CDATA[virtual-threads]]></category>
            <category><![CDATA[platform-thread]]></category>
            <category><![CDATA[java-thread]]></category>
            <dc:creator><![CDATA[sachinda nipun]]></dc:creator>
            <pubDate>Sun, 11 Oct 2026 20:15:35 GMT</pubDate>
            <atom:updated>2026-10-11T20:15:35.025Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*eok2ViXaEaI-gsqTFYhvwg.png" /></figure><p>Virtual threads are lightweight threads that help reduce the effort of writing, managing and debugging high-throughput concurrent applications.</p><p>A thread is the smallest unit of processing that can be scheduled. To a large extent, threads run independently of each other. A thread is an instance of java.lang.Thread. There are two types of threads in Java: platform threads and virtual threads.</p><p>In this article, we are going to talk about the following topics:</p><ul><li>What is a platform thread?</li><li>What is a virtual thread?</li><li>Why use virtual threads?</li><li>How to create a virtual thread</li><li>Scheduling virtual threads and pinned virtual threads</li><li>Debugging virtual threads</li><li>Virtual thread usage guidance</li></ul><h3>What is a platform thread?</h3><p>A platform thread is a thin wrapper around an OS thread. It runs Java code on that OS thread and holds it for its whole lifetime, until the platform thread is finished. Because of this, the number of platform threads you can have is limited to the number of OS threads.</p><p>Normally, platform threads have a large thread stack and other resources maintained by the operating system. Even though they are suitable for running any kind of task, they can be a limited resource.</p><h3>What is a virtual thread?</h3><p>Like a platform thread, a virtual thread is also an instance of java.lang.Thread. However, a virtual thread isn’t tied to a specific OS thread, but it still runs on an OS thread.<strong> When a virtual thread starts a blocking I/O operation, the Java runtime suspends it until it is ready to continue</strong>. The OS thread that was running the virtual thread is then free to run another virtual thread.</p><p>Virtual threads usually have a shallow call stack. A virtual thread might only do one HTTP call or one database query and then finish. They support thread-local variables, but you should be careful with them because one JVM can run millions of virtual threads at the same time.</p><blockquote>Virtual threads are good for tasks that spend most of their time waiting, for example waiting for I/O. They are not made for long-running, CPU-heavy work.</blockquote><h3>Why use virtual threads?</h3><p>Virtual threads are useful in applications that handle a lot of concurrent tasks, where most of those tasks spend their time waiting. A server application is a good example. A server handles many client requests, and each request usually waits for things like a database, a file or another service.</p><blockquote>One important thing to understand is that virtual threads are not faster threads. They don’t run your code any faster than platform threads. What they give you is scale. You can handle many more requests at the same time (higher throughput), but each request doesn’t become faster (latency stays the same).</blockquote><h3>How to create a virtual thread</h3><p>Java gives us a few ways to create virtual threads.</p><p>The simplest way is Thread.ofVirtual():</p><pre>Thread thread = Thread.ofVirtual().start(() -&gt; System.out.println(&quot;Hello from a virtual thread&quot;));<br>thread.join();</pre><p>We call join() here so the main thread waits until the virtual thread finishes. Otherwise the program might end before the message is printed.</p><p>If you want to give your threads names, you can use the Thread.Builder interface:</p><pre>Thread.Builder builder = Thread.ofVirtual().name(&quot;worker-&quot;, 0);<br><br>Thread t1 = builder.start(() -&gt; System.out.println(&quot;Running in &quot; + Thread.currentThread().getName()));<br>Thread t2 = builder.start(() -&gt; System.out.println(&quot;Running in &quot; + Thread.currentThread().getName()));<br><br>t1.join();<br>t2.join();</pre><p>This creates threads named worker-0 and worker-1.</p><p>In real applications, you will probably use an ExecutorService. The Executors.newVirtualThreadPerTaskExecutor() method creates a new virtual thread for every task you submit:</p><pre>try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {<br>    Future&lt;String&gt; result = executor.submit(() -&gt; &quot;Task done&quot;);<br>    System.out.println(result.get());<br>}</pre><p>Because the executor is used inside a try-with-resources block, close() is called at the end, and it waits until all submitted tasks are finished.</p><h3>Virtual thread usage guidance</h3><p>Virtual threads are still java.lang.Thread, so there is nothing new to learn. But some old habits from platform threads don’t work well with them.</p><p><strong>1. Write simple, blocking code.</strong> Blocking a virtual thread is cheap, so you don’t need complex async chains. Normal step-by-step code is easier to read and debug, and it gets the most benefit from virtual threads.</p><p><strong>2. Don’t pool virtual threads.</strong> Each virtual thread should be one task, not a shared resource. Use Executors.newVirtualThreadPerTaskExecutor() instead of a fixed thread pool, and create a new virtual thread even for small tasks.</p><p><strong>3. Use a Semaphore to limit concurrency.</strong> If a service can only handle 10 calls at once, don’t use a pool of 10 threads. Use a Semaphore:</p><pre>Semaphore semaphore = new Semaphore(10);<br><br>semaphore.acquire();<br>try {<br>    return limitedService.call();<br>} finally {<br>    semaphore.release();<br>}</pre><p><strong>4. Don’t cache expensive objects in ThreadLocal.</strong> Virtual threads are never reused, so every task creates its own copy, which wastes memory. For example, use a shared DateTimeFormatter instead of caching a SimpleDateFormat in a ThreadLocal.</p><p><strong>5. Watch out for long blocking calls inside </strong><strong>synchronized.</strong> On JDK 21, doing long I/O inside a synchronized block keeps the virtual thread stuck to its OS thread (this is called pinning). If it happens often, use a ReentrantLock instead. From JDK 24, this problem is fixed for synchronized.</p><h3>Conclusion</h3><p>Virtual threads don’t make your code faster, but they let your application handle many more tasks at the same time with simple, readable code. If you are building servers or services that spend most of their time waiting for I/O, they are worth trying. Just remember to stop pooling them, keep your code blocking and simple, and watch out for pinning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8609a4babef2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beyond the Chat Window: 5 Reality Shifts in the 2026 AI Coding Landscape]]></title>
            <link>https://medium.com/@sachindanipun96/beyond-the-chat-window-5-reality-shifts-in-the-2026-ai-coding-landscape-edbd69869188?source=rss-89cccac1ccc------2</link>
            <guid isPermaLink="false">https://medium.com/p/edbd69869188</guid>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[sachinda nipun]]></dc:creator>
            <pubDate>Fri, 30 Jan 2026 08:47:09 GMT</pubDate>
            <atom:updated>2026-01-30T08:47:09.018Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re still copy-pasting snippets into a ChatGPT window, I hate to break it to you: you’re already writing legacy code.</p><p>The evolution we’ve seen over the last three years is nothing short of breathtaking. In 2023, AI was a novelty living in a secondary chat window. By 2024, it crawled into our editors. In 2025, it became the core of the development workflow. Today, in 2026, the “chat box” era is dead. AI isn’t just a guest in your IDE; it’s the foundation of the entire software lifecycle.</p><p>As a strategist who lives in these tools daily, I’ve seen the landscape shift from simple autocompletions to autonomous agents. Here are the five reality shifts you need to master to stay relevant in the age of agentic development.</p><p><strong>1. The IDE is Now an Agent, Not a Text Editor</strong></p><p>We’ve moved past the era of the “smart editor.” Today, your environment is an active participant. While traditionalists might stick with VS Code and GitHub Copilot, those on the bleeding edge have moved to tools like <strong>Cursor</strong> — a VS Code fork rebuilt from the ground up for AI — or specialized high-performance editors like <strong>Zed</strong> and Google’s <strong>Anti-gravity</strong>.</p><p>The biggest shift here is “agentic behavior.” In Cursor, for example, you no longer just “type.” You orchestrate through four specific modes:</p><p>• <strong>Agent:</strong> For autonomous, multi-line edits across your codebase.</p><p>• <strong>Plan:</strong> For deep architectural mapping before a single character is committed.</p><p>• <strong>Debug:</strong> Focused entirely on diagnosing and squashing errors.</p><p>• <strong>Ask:</strong> A read-only mode for exploring and understanding complex logic.</p><p>Beyond the IDE, we’ve seen the rise of CLI agents like <strong>Claude Code</strong>. Unlike an IDE extension, Claude Code lives in your terminal, understands your entire repo, and can spawn “sub-agents” to handle parallel tasks. The caveat? It only works with Claude models.</p><p>But with this power comes a warning: AI <strong>“occasionally breaks things with great confidence.”</strong> As these tools become more autonomous, your role shifts from “writer” to “supervisor.” If you aren’t auditing the output, you aren’t developing; you’re just accumulating high-speed technical debt.</p><p><strong>2. From Jira Tickets to Code: The Visual and Collaborative Shift</strong></p><p>The most counter-intuitive shift in 2026 is that AI development is moving <em>outside</em> the editor. For front-end heavy work and cross-team collaboration, tools like <strong>Builder.io</strong> are changing the game by adding a Figma-like visual layer directly over your codebase.</p><p><em>Full disclosure: I work at Builder, so I see these “insider” shifts firsthand.</em> We’re seeing a world where a Product Manager can take a Slack conversation or a Jira ticket and turn it directly into a code change through this visual layer. This isn’t just about making developers faster; it’s about collapsing the distance between design, product, and engineering. When the AI understands your design system as well as your codebase, the “hand-off” becomes a relic of the past.</p><p><strong>3. The Specialized Assistant: Claude vs. The World</strong></p><p>While we have specialized app builders like <strong>Replit</strong>, <strong>Lovable</strong> (great for React/Tailwind), and <strong>Bolt</strong> (which offers more stack flexibility), the heavy lifting still happens in the conversation.</p><p><strong>Claude (specifically Opus 4.5)</strong> has become the definitive “takeaway” choice for high-stakes engineering. It is more deliberate and handles massive context windows with a level of architectural reasoning that faster models often miss. It is the tool I never close.</p><p><strong>Pro-Tip: The Triple-Threat Strategy</strong> ChatGPT, Claude, and Gemini are all incredibly capable, and they all offer free tiers. If you hit the daily usage limit on Claude during a heavy refactor, don’t stop — just pivot your context to ChatGPT or Gemini. Each has unique strengths, but in 2026, they are all viable primary partners.</p><p><strong>4. Catching Bugs Before They Exist: AI as the Ultimate Reviewer</strong></p><p>The sheer volume of AI-generated code means human PR reviews are no longer enough. We now use AI to watch the AI.</p><p>• <strong>AI Code Review:</strong> Tools like <strong>Code Rabbit</strong> and Cursor’s <strong>Bugbot</strong> are now standard. Code Rabbit performs line-by-line reviews and actually learns from your feedback over time, aligning itself with your team’s specific style.</p><p>• <strong>The Security Guard:</strong> <strong>Snyk</strong> has evolved from a simple linter to a full-stack protector, scanning dependencies, containers, and infrastructure before a single line hits production.</p><p>• <strong>The Debugging Leap:</strong> Perhaps the most “surprising” leap is <strong>JAM</strong>. We’ve all dealt with the “it works on my machine” nightmare. JAM kills this by automatically capturing video replays, console logs, network requests, and environment details the moment a bug occurs. You can then hand that rich data to an AI and ask it to suggest a fix. It’s not just an update; it’s a total revolution in how we handle production failures.</p><p><strong>5. Three “Pro Tips” to Master the 2026 Workflow</strong></p><p>To get the most out of this agentic world, you have to stop treating AI like a search engine and start treating it like a pair programmer.</p><p>1. <strong>Plan Before You Execute:</strong> Most devs fail by saying “build me this.” Instead, use “Plan Mode” to ask for a step-by-step outline first. It saves tokens, time, and prevents the AI from falling down a hallucination rabbit hole.</p><p>2. <strong>Teach the AI Your Project Once:</strong> Stop repeating yourself. Use project context files like clot.md or <strong>cursor rules and agents.md</strong>. These files act as a permanent manual for the AI, storing your architectural patterns and coding standards so it stays consistent without being reminded.</p><p>3. <strong>Make the AI Ask the Questions:</strong> Before letting the AI write a single line, force it to ask <em>you</em> clarifying questions about requirements and edge cases. This forces a collaborative “check-and-balance” that eliminates half-baked solutions.</p><p><strong>Conclusion: </strong>The Knowledge Paradox</p><p>We are surrounded by tools that can ship entire features end-to-end. But this has created the “Knowledge Paradox”: as the tools handle more of the <em>how</em>, your understanding of the <em>why</em> becomes your only real value.</p><p>If you don’t understand the fundamentals, you aren’t a supervisor; you’re a liability. This is why continuous learning through platforms like <strong>Scrimba</strong> — with their 100-hour full-stack paths — is more critical now than it was five years ago. You need to understand the logic to prevent “Supervisory Debt.”</p><p>As AI moves from a tool to a teammate, the question isn’t whether it will replace you, but whether you are capable of leading the team. How are you evolving your workflow today?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edbd69869188" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decoding Spring Security: Understanding the Inner Workings of Authentication and Authorization in a…]]></title>
            <link>https://medium.com/@sachindanipun96/decoding-spring-security-understanding-the-inner-workings-of-authentication-and-authorization-in-a-f5aac86dd9c0?source=rss-89cccac1ccc------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5aac86dd9c0</guid>
            <category><![CDATA[jwt-token]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[spring-security]]></category>
            <dc:creator><![CDATA[sachinda nipun]]></dc:creator>
            <pubDate>Sat, 10 Feb 2024 09:14:46 GMT</pubDate>
            <atom:updated>2024-02-10T09:18:35.175Z</atom:updated>
            <content:encoded><![CDATA[<h3>Decoding Spring Security: Understanding the Inner Workings of Authentication and Authorization in a Spring Boot Application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*H1zTl9sprZ2jZc785XItNg.jpeg" /></figure><p>We can see a lot of Spring Security tutorials, and they mention how to enable security and the structure to build security for the application. However, it’s hard to find a good article to understand the security class and security flow in a Spring Boot application. Today, we are going to understand the roles of classes and interfaces that support the security process.</p><p>This class helps with both Authentication and Authorization. I assume you already have a clear idea about Authentication, Authorization, and JWT. In our application, we were using JWT-based security validation.</p><p>Let’s start.</p><p>First, identify the diagram below. Then, we will talk about each class one by one. If you need to understand the implementation, please refer to my project. <a href="https://github.com/sachinda96/SesureVault.git">https://github.com/sachinda96/SesureVault.git</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*SqBjVrYg1qqCBeUxtzAchg.png" /></figure><p><strong>JwtAuthenticationFilter</strong>:</p><p>When the application receives a request, it first reaches the JwtAuthenticationFilter class. This class can validate the request and response. With the request and responses, the application can validate the authentication data and headers to identify the user. According to the diagram above, this class routes the user information to verify if the user came with the correct credentials. We will discuss this later. Also, we can see that this class has extended a class called OncePerRequestFilter. What is that? It is a framework class used to filter requests. If we need to intercept the request before calling the controller, we have to filter the request with a filter class. However, a filter class can be called several times because it is invoked multiple times to handle the request. So, OncePerRequestFilter solves this issue. If we extend this class, it ensures that it is called only once per request, avoiding duplicated implementation. This means a Single Execution Guarantee.</p><p><strong>JwtServiceImpl</strong>:</p><p>The <strong>JwtAuthenticationFilter</strong> is the first call to the <strong>JwtServiceImpl</strong> once it extracts the token to get the user information. This class has several methods. You can refer to my project. The methods are used to generate, validate, and extract claims from the token. We will discuss the JWT token in another article.</p><p>Once the <strong>JwtAuthenticationFilter</strong> receives the user information, the username is passed to the UserService to get the UserDetails from the database.</p><p><strong>UserService</strong>:</p><p>It is the Spring Security package interface and the method <strong>`loadUserByUsername(username)`</strong> is used to get the user information. When this method is called, it definitely calls the implementation class, which has implemented the logic to fetch the information from the database.</p><p>Once the user information is received, the <strong>JwtAuthenticationFilter</strong> creates a <strong>UsernamePasswordAuthenticationToken</strong> object. It holds the user information (username, password, etc.) along with Role information. Additionally, it binds the request to that object. Afterward, it generates an auth token for this request thread.</p><p>After that, this auth token is set to the <strong>SecurityContext</strong>. The SecurityContext holds the user information and user authorities (Roles). This allows Spring Security to maintain information about the authenticated user throughout the session, enabling subsequent authorization checks and access control based on the user’s identity and authorities.</p><p>Once the above processes are completed successfully, the request goes to the controller to call the corresponding method.</p><p><strong>SecurityConfig</strong>:</p><p>The <strong>SecurityConfig</strong> class allows you to customize various aspects of security in your Spring Boot application, such as authentication mechanisms, access control rules, and login/logout behavior.</p><p><strong><em>What questions do you have? </em></strong>When I was studying, I had a big question about the following scenario. We mentioned before that every request is handled by OncePerRequestFilter, and it has been extended to JwtAuthenticationFilter. Jwt validates all tokens, and if there is no token in the request, it returns an error. So, how does it work when we permit all for a specific URL in the configuration? How does it work? Simply put, if we define permit all for a specific request, OncePerRequestFilter is not called.</p><p>We will discuss how authorization works and what the roles are in the next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5aac86dd9c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Containerize and Streamline Software Deployment with Docker: A Beginner’s Guide]]></title>
            <link>https://medium.com/@sachindanipun96/how-to-containerize-and-streamline-software-deployment-with-docker-a-beginners-guide-17a7dead0ef6?source=rss-89cccac1ccc------2</link>
            <guid isPermaLink="false">https://medium.com/p/17a7dead0ef6</guid>
            <category><![CDATA[docker-beginner]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[sachinda nipun]]></dc:creator>
            <pubDate>Sat, 27 Jan 2024 11:34:30 GMT</pubDate>
            <atom:updated>2024-01-27T11:36:46.237Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Knxbz_BI_QYFgxdW76BPg.png" /><figcaption>Docker Basics</figcaption></figure><p>Docker is an incredibly important and popular tool in today’s software development landscape. In this article, we will delve into the basics of Docker, providing valuable insights for beginners eager to grasp fundamental concepts.</p><p>Let’s begin…</p><h3><strong>What is Docker?</strong></h3><p>Docker serves as a powerful tool for the efficient development, testing, and deployment of software products. It operates within containers, where the software product is executed. Notably, Docker eliminates the need to consider software packages, libraries, and other components when releasing a project to testing or production environments. Instead, everything is neatly packed into a Docker container. If this seems perplexing, let’s elucidate with real-world examples.</p><p>Imagine you’ve developed a webpage that relies on various libraries and dependencies for smooth execution. Additionally, your development environment may include specific components. Now, your team lead or manager instructs you to release the project to the testing environment for QA testing. What’s your approach? You could document all the steps, detailing the components to be installed, required libraries, and more. However, this manual approach is cumbersome. Enter Docker — a solution that allows you to encapsulate all these requirements within a Dockerfile, facilitating the creation of Docker images for your projects. These images specify what needs to be installed or linked when running the container.</p><p>Now, let’s delve into the Dockerfile.</p><p>Stay tuned for more insights into the world of Docker in the upcoming sections!</p><h3><strong>Dockerfile</strong></h3><p>A docker file is just a text file that mentions the instructions on how should we build the docker image. Here is the basic structure of the docker file.</p><pre># Use an official base image<br>FROM base_image:tag<br><br># Set the working directory in the container<br>WORKDIR /app<br><br># Copy the application files into the container<br>COPY . .<br><br># Install dependencies (if needed)<br>RUN apt-get update &amp;&amp; apt-get install -y dependency_package<br><br># Expose a port (if needed)<br>EXPOSE 80<br><br># Define environment variables (if needed)<br>ENV ENV_VARIABLE=value<br><br># Specify the command to run the application<br>CMD [&quot;command&quot;, &quot;arg1&quot;, &quot;arg2&quot;]<br></pre><p><strong>Explanation of key Dockerfile instructions:</strong></p><p><strong>FROM:</strong> Specifies the base image for your application. You can use an official image or create your custom base image.</p><p><strong>WORKDIR:</strong> Sets the working directory inside the container.</p><p><strong>COPY:</strong> Copies files from the host machine into the container.</p><p><strong>RUN:</strong> Executes commands during the image build process, typically used for installing dependencies.</p><p><strong>EXPOSE:</strong> Inform Docker that the application inside the container will listen on the specified network ports at runtime.</p><p><strong>ENV:</strong> Sets environment variables that will be available during the container runtime.</p><p><strong>CMD:</strong> Specifies the default command to run when the container starts. This can be overridden when running the container.</p><p><strong>Build the Docker Image</strong></p><p><strong><em>Note: This assumes the Dockerfile is in the current directory (.)</em></strong></p><pre>docker build -t image_name:tag .</pre><p><strong>Check the Created Docker Image</strong></p><p><strong><em>Note: The following command will retrieve the list of created docker images list</em></strong></p><pre>docker images</pre><p><strong>Run the Docker Image</strong></p><p>Ok fine. now we are on the game. we have a few steps to complete to run the docker image. As we know once it runs it calls a container.</p><p>We can use the following command to run the docker image.</p><p>To run a Docker image, you can use the `docker run` command. Here’s a basic example:</p><pre>docker run -p 8080:8080 your-app-image</pre><p>This command does the following:</p><ul><li>`docker run`: Starts a new container.</li><li>`-p 8080:8080`: Maps port 8080 on the host to port 8080 on the container. Adjust the ports as needed.</li><li>`your-app-image`: Specifies the name or ID of the Docker image you want to run.</li></ul><p>If you have additional options or need to provide runtime arguments to your application, you can include them at the end of the `docker run` command. For example:</p><pre>docker run -p 8080:8080 your-app-image - some-argument=value</pre><p>Replace `your-app-image` with the actual name or ID of your Docker image, and adjust the port mappings and arguments based on your application’s requirements.</p><p>Keep in mind that the container will run in the foreground by default. If you want to run the container in the background (detached mode), you can add the `-d` option:</p><pre>docker run -d -p 8080:8080 your-app-image</pre><p>To view the logs of a running container, you can use the `docker logs` command:</p><pre>docker logs container_id_or_name</pre><p>Replace `container_id_or_name` with the actual ID or name of your running container.</p><p>Remember to replace placeholder values with your actual image name, container ID, or specific configurations.</p><h3><strong>What is a docker container?</strong></h3><p>A Docker container is a lightweight, standalone, and executable software package that includes everything needed to run a piece of software, including the code, runtime, libraries, system tools, and settings. Containers are isolated from each other and the underlying host system, providing consistency and portability across different environments.</p><p><strong>Run the Docker Container:</strong></p><p>As we discussed before, once the image is built, you can run a container</p><pre>docker run -p 8080:8080 your-app-image</pre><p>This command starts a container based on the image, mapping port 8080 on your local machine to port 8080 in the container.</p><p><strong>Container Operations:</strong></p><p>You can check the running containers using:</p><pre>docker ps</pre><p>To stop and remove the container:</p><pre>docker stop container_id<br>docker rm container_id</pre><p>Replace container_id with the actual ID of your running container.</p><p>Now we have a basic idea and we can run our project with docker. We will discuss deeper about docker in the next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17a7dead0ef6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>