<?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 Nitin Manju on Medium]]></title>
        <description><![CDATA[Stories by Nitin Manju on Medium]]></description>
        <link>https://medium.com/@nitinmanju?source=rss-ea1e000d6e29------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6-xbueEbymkVLCNg.jpeg</url>
            <title>Stories by Nitin Manju on Medium</title>
            <link>https://medium.com/@nitinmanju?source=rss-ea1e000d6e29------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 12:20:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nitinmanju/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[Docker 105 — Building a multilayer Docker image]]></title>
            <link>https://nitinmanju.medium.com/docker-105-building-a-multilayer-docker-image-70c086fcb672?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/70c086fcb672</guid>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[docker-101]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Sun, 20 Aug 2023 20:52:08 GMT</pubDate>
            <atom:updated>2023-08-21T08:11:56.960Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker 105 — Building a multilayer Docker image</h3><p>In the <a href="https://medium.com/@nitinmanju/docker-104-dockerfile-instructions-in-detail-64854c577cee">previous chapter</a>, we understood the essential instructions required to build a Dockerfile, it&#39;s time we build a Dockerfile using the knowledge we have gained. Let us build a Dockerfile that builds and runs an API application using .NET, ASP.NET Core and C#, the API application will be used to manage a ToDo list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*snqdRvaoItp8BxP7_9kDfw.jpeg" /></figure><h4>This Dockerfile will do the following</h4><ol><li>It should set up the base image for the container</li><li>It should build the API application from the source code</li><li>It should set up the startup logic for the API application (<em>ENTRYPOINT</em>)</li></ol><h4>Let&#39;s begin</h4><p>If you have never worked with <a href="https://dotnet.microsoft.com/en-us/apps/aspnet/apis">.NET and ASP.NET Core WebAPI</a> before, that’s fine. Follow along, it’s super simple.</p><p><strong>Important Note 1:</strong> You will require the d<a href="https://dotnet.microsoft.com/en-us/download">otnet (.NET) 7 SDK</a> installed on your local machine, and I will be using the Visual Studio Code editor in this lecture.</p><p><strong>Important Note 2: </strong>To keep the lecture short, we will not focus much on the application logic but instead focus more on the Dockerfile. You can get the full application code <a href="https://github.com/nitin-manju/DockerSamples/tree/main/MultilayerBuild/src/todo-api">here</a>. It is recommended that you clone it and move along with the chapter.</p><p>We will start by importing the base image which is the runtime for our API application. We will start by creating a blank Dockerfile and progressively updating it throughout the chapter.</p><h4>Create the ASP.NET Core API application</h4><p>Run each line in the same directory as the Dockerfile created above.</p><pre>mkdir src<br>cd src<br>dotnet new webapi --name todo-api<br>cd todo-api</pre><p>Create a new Dockerfile inside the todo-api directory and we can start adding the instructions. The content of the directory should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*k4FQrTbi3ObPuQFpGT909A.png" /></figure><p>Let us modify our application a bit to serve the purpose of a to-do application. Delete the <strong><em>Controllers/WeatherForecastController</em></strong> and the <strong><em>WeatherForecast.cs</em></strong> files. Add a new file under the Controllers directory, let&#39;s call it <strong><em>TodoController.cs</em></strong><em> </em>and replace the content with the following:</p><pre>using Microsoft.AspNetCore.Mvc;<br>namespace todo_api.Controllers;<br><br>[ApiController]<br>[Route(&quot;[controller]&quot;)]<br>public class TodoController : ControllerBase<br>{<br>    private static readonly List&lt;ToDo&gt; _todoItems = new();<br><br>    public TodoController() {}<br><br>    [HttpGet(Name = &quot;GetMyItems&quot;)]<br>    public IEnumerable&lt;ToDo&gt; Get()<br>    {<br>        return _todoItems;<br>    }<br><br>    [HttpPost(Name = &quot;CreateItem&quot;)]<br>    public ToDo Post([FromBody] ToDo item)<br>    {<br>        var lastItem = _todoItems.LastOrDefault();<br>        item.Id = lastItem == null ? 1 : lastItem.Id + 1;<br><br>        _todoItems.Add(item);<br>        return item;<br>    }<br><br>    [HttpPut(&quot;{id:double}&quot;, Name = &quot;UpdateItem&quot;)]<br>    public IActionResult Put([FromRoute] double id, [FromBody] ToDo item)<br>    {<br>        var found = _todoItems.Find(item =&gt; item.Id == id);<br>        if (found == null)<br>            return NotFound();<br><br>        found.IsCompleted = item.IsCompleted;<br>        return Ok(found);<br>    }<br><br>    [HttpDelete(&quot;{id:double}&quot;, Name = &quot;DeleteItem&quot;)]<br>    public IActionResult Delete([FromRoute] double id)<br>    {<br>        var found = _todoItems.Find(item =&gt; item.Id == id);<br>        if (found == null)<br>            return NotFound();<br><br>        _todoItems.Remove(found);<br>        return Ok(true);<br>    }<br>}<br><br>public class ToDo<br>{<br>    public long? Id { get; set; }<br>    public string Title { get; set; } = &quot;&quot;;<br>    public bool IsCompleted { get; set; }<br>}</pre><p>The new structure should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*Dop08k-7aln80ulsiuVntQ.png" /></figure><p>Edit the <strong><em>Program.cs</em></strong> file to the following:</p><pre>var builder = WebApplication.CreateBuilder(args);<br>builder.Services.AddControllers();<br>builder.Services.AddEndpointsApiExplorer();<br>builder.Services.AddSwaggerGen();<br><br>var app = builder.Build();<br>app.UseSwagger();<br>app.UseSwaggerUI();<br>app.UseHttpsRedirection();<br>app.UseAuthorization();<br>app.MapControllers();<br>app.Run();</pre><p>Let’s start working on the Dockerfile. We will create multiple layers for each step.</p><h4>Step 1: Setup the base image</h4><pre>FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base</pre><p>Notice that we have used the “AS base” this is to set the image <em>“mcr.microsoft.com/dotnet/aspnet:7.0”</em> as the base runtime image which can be referenced later. We will set up a working directory, let&#39;s call it “app” and we will be using Port 80 for the endpoints. So let&#39;s expose this port.</p><pre>FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base<br>WORKDIR /api<br>EXPOSE 80</pre><p>Now that we have set a base image, we are going to move the build phase into the Dockerfile.</p><h4>Step 2: Setup the build phase</h4><p>Add a new image from <em>“mcr.microsoft.com/dotnet/sdk:7.0” </em>SDK as build</p><pre>FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base<br>WORKDIR /api<br>EXPOSE 80<br><br>FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build<br>WORKDIR /build<br>COPY . .</pre><p>Set the WORKDIR as “/build” and copy the source code to this current working directory using the COPY . . instruction. This will copy all the files from the current build context, which is the <em>todo-api</em> directory. Hence all the files and directories in the build context will be copied to the current WORKDIR location which is /build</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*mNy1ndHarHgYUfFBCk6xHg.png" /></figure><p>Notice that we have added a new file called <em>.dockerignore</em>, this is a special file that helps docker identify the files and the directories it should ignore during the build time.</p><p><strong>Note</strong>: If you have not cloned the project, <a href="https://github.com/nitin-manju/DockerSamples/blob/main/MultilayerBuild/src/todo-api/.dockerignore">take a look inside</a> the file and create your own.</p><p>We can now run some dotnet commands inside the docker build process using the RUN instruction. Let us first restore the project using the <em>dotnet restore</em> command and then build the project using the <em>dotnet build</em> command. The updated Dockerfile should look like this.</p><pre>FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base<br>WORKDIR /api<br>EXPOSE 80<br><br>FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build<br>WORKDIR /build<br>COPY . .<br>RUN dotnet restore &quot;todo-api.csproj&quot;<br>RUN dotnet build &quot;todo-api.csproj&quot; -o /app/build</pre><p>After building the project, we are now ready to publish the build, but before we do that, we will alias the build image with a new name as publish and then RUN the <em>dotnet publish</em> command. Let’s update the Dockerfile</p><pre>FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base<br>WORKDIR /api<br>EXPOSE 80<br><br>FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build<br>WORKDIR /build<br>COPY . .<br>RUN dotnet restore &quot;todo-api.csproj&quot;<br>RUN dotnet build &quot;todo-api.csproj&quot; -o /app/build<br><br>FROM build AS publish<br>RUN dotnet publish &quot;todo-api.csproj&quot; -c release -o /app/publish</pre><p>The output of the publish command has been set to /app/publish within the Docker build layer.</p><h4>Step 3: Setup the runtime/startup</h4><p>We will now go back to the base image (set in Step 1) which will be used as the final runtime image. We will copy the published binaries into the /api directory and then execute the application dll using the ENTRYPOINT</p><p>This is the final stage, let&#39;s update the Dockerfile one last time and then build it.</p><pre># Setup<br>FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base<br>WORKDIR /api<br>EXPOSE 80<br><br># Build stage<br>FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build<br>WORKDIR /build<br>COPY . .<br>RUN dotnet restore &quot;todo-api.csproj&quot;<br>RUN dotnet build &quot;todo-api.csproj&quot; -o /app/build<br><br>FROM build AS publish<br>RUN dotnet publish &quot;todo-api.csproj&quot; -c release -o /app/publish<br><br># Runtime stage<br>FROM base AS final<br>WORKDIR /api<br>COPY --from=publish /app/publish .<br>ENTRYPOINT [&quot;dotnet&quot;, &quot;todo-api.dll&quot;]</pre><p>We have successfully created a Dockerfile with multiple layers, it&#39;s time to build and test it.</p><pre>docker build .</pre><p>The first build should take some time, however, consecutive builds should be much faster. The output should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kIHyhH5UUKmS8KG_mqM3MA.png" /><figcaption>docker build log</figcaption></figure><p>We have exposed port 80 within the Dockerfile. Run the built image using docker run and map it to a port on the host machine using the -p flag as shown below.</p><p><strong>Note</strong>: the image id will differ on your machine (duh!)</p><pre>docker run -p 8090:80 276d784c925787a6148230f7b5b</pre><p>We are running the container on port 8090 on the host machine which is mapped to port 80 inside the container. If everything is built right, you can navigate to the URL: <a href="http://localhost:8090/swagger/index.html">http://localhost:8090/swagger/index.html</a> to load the Swagger UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gMM6OlbCKp2W-yEqsIEMWg.png" /><figcaption>Swagger loaded from within the container</figcaption></figure><p>If you are familiar with Postman, then you can go ahead and test the API.</p><p>You have successfully created a Dockerfile from scratch. In the next chapter, We will learn about running multiple docker images. Hope you have enjoyed this post. Stay tuned for more Docker 101!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70c086fcb672" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker 104 — Dockerfile instructions in detail]]></title>
            <link>https://nitinmanju.medium.com/docker-104-dockerfile-instructions-in-detail-64854c577cee?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/64854c577cee</guid>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-introduction]]></category>
            <category><![CDATA[docker-101]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Fri, 18 Aug 2023 21:17:09 GMT</pubDate>
            <atom:updated>2023-08-20T20:58:21.451Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker 104 — Dockerfile instructions in detail</h3><p>In the previous <a href="https://nitinmanju.medium.com/docker-103-building-an-image-using-dockerfile-caf99397fb48">chapter</a>, we understood how the build process works and we also created a simple Dockerfile. In this section, we will discuss a bit more about Dockerfile capabilities and the various commands that we can use. We will only discuss the bare minimum required to build a working Dockerfile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rMWZWcK3bPGTtVpZoxq4uQ.png" /></figure><h3>Dockerfile instruction explained</h3><p>Below we will discuss the most used Dockerfile instructions which will help you build a basic as well as an advance Dockerfile. Let&#39;s begin!</p><h4>FROM</h4><p>We have mainly been talking about the FROM instruction, the syntax is as below:</p><pre>FROM [--platform=&lt;platform&gt;] &lt;image&gt; [AS &lt;name&gt;]</pre><p>This can be used multiple times in a Dockerfile and usually sets the build stage in the form of a base image for the next set of instructions until a new FROM instruction is issued. AS &lt;name&gt;is an optional argument and is used to provide an alias to this layer which can be referenced at a later point. The --platform=&lt;platform&gt; flag is optional and is used to define the platform of the image used in the FROM instruction in case a multi-platform image is targeted. Values for this flag can include linux/amd64, linux/arm64, or windows/amd64 . FROM is usually the first instruction in a Dockerfile. However, only ARG instruction(explained later) can precede the FROM instruction at the beginning of a Dockerfile in certain scenarios and these two can work together.</p><h4>CMD</h4><p>The CMD instruction is mainly used to provide default execution parameters when a container instance is run. In a Dockerfile, there can be only one CMD instruction. If multiple CMD is provided, the last occurrence is the only instruction executed. It has to be noted that, the CMD command and parameters can be overridden when the container is run.</p><p>There are three ways to represent theCMD instruction. In the JSON array format, here the instruction will run the <em>executable </em>and pass the <em>param1 </em>and <em>param2 </em>to the executable. This is the JSON array or exec form of expressing the defaults.</p><pre>CMD [&quot;executable&quot;,&quot;param1&quot;,&quot;param2&quot;]</pre><p>The CMD can also be provided in a shell form. Here, the <em>command </em>is the executable and <em>param1</em> and <em>param2 </em>are passed as the parameters to it.</p><pre>CMD command param1 param2</pre><p>There is a third way of providing default parameters to the executable but this works in hand with the ENTRYPOINT instruction (explained next).</p><pre>CMD [&quot;param1&quot;,&quot;param2&quot;]</pre><p>Here the executable is provided by the ENTRYPOINT instruction and CMD only provides the default parameters. In this method, both CMD and ENTRYPOINT instructions become mandatory in the Dockerfile.</p><h4>ENTRYPOINT</h4><p>The ENTRYPOINT Docker instruction is used to specify the command that will be executed when a Docker container starts. It allows you to set a default executable for the container, which can be combined with other commands or arguments when the container is run. Unlike CMD, ENTRYPOINT parameters are not easily overridden. This instruction is often used to define the primary application or process that runs within the container, ensuring consistency and predictability in container behaviour across different environments.</p><p>The syntax for the ENTRYPOINT instruction looks as below:</p><pre>ENTRYPOINT [&quot;executable&quot;, &quot;param1&quot;, &quot;param2&quot;]</pre><p>Just like the CMD instruction, it can also be used in the shell form:</p><pre>ENTRYPOINT command param1 param2</pre><p>Only the last ENTRYPOINT instruction in the Dockerfile will have an effect.</p><h4>WORKDIR</h4><p>The WORKDIR Docker instruction is used to set the working directory for any subsequent instructions within a Dockerfile. By specifying a directory path as an argument to WORKDIR, you define the location where commands like RUN, COPY, and ADD will be executed. This helps organize and streamline container operations by providing a consistent context for these commands. If the directory doesn&#39;t exist, WORKDIR will create it. This instruction is valuable for improving code readability, maintaining a structured file hierarchy, and ensuring that container operations are conducted in the intended directory, enhancing Dockerfile clarity and maintainability.</p><p>The syntax is very simple:</p><pre>WORKDIR /path/to/workdir</pre><p>If you run multiple WORKDIR instructions, the final working directory will be the result of every WORKDIR instruction combined.</p><pre>WORKDIR /dir1<br>WORKDIR dir2<br>WORKDIR dir3<br>ENTRYPOINT [ &quot;pwd&quot; ]</pre><p>Try this yourself using the Dockerfile example below, the output of the <em>pwd </em>command will be <em>/dir1/dir2/dir3</em></p><pre>docker build https://github.com/nitin-manju/DockerSamples.git#main:InstructionSamples/WORKDIR</pre><h4>COPY</h4><p>The COPY Docker instruction facilitates the copying of files and directories from the host machine into a Docker image during the build process. It requires two arguments: the source path (relative to the context of the build) and the destination path within the image. This instruction is useful for incorporating application code, configuration files, and other assets into the image. COPY solely deals with file system content and doesn&#39;t perform URL retrieval or unpacking. It helps maintain a more straightforward and predictable image construction process, enhancing Dockerfile clarity and reproducibility.</p><p>The syntax is simple:</p><pre>COPY &lt;src&gt;... &lt;dest&gt;</pre><p>Multiple source paths can be given and they all work as relative paths under the build context.</p><p>If the paths have whitespaces, an alternative method can be used :</p><pre>COPY [&quot;&lt;src&gt;&quot;,... &quot;&lt;dest&gt;&quot;]</pre><p>wildcard characters like * and ? can be used in the source paths to match the file names.</p><pre>COPY resource-* /resources/<br>COPY resource-x? /resources/</pre><p>If a WORKDIR instruction is been added before the COPY instruction, the destination path will be relative to the WORKDIR directory.</p><h4>ADD</h4><p>The ADD Docker instruction serves to incorporate files and directories from the build context or remote URLs into a Docker image during construction. It functions similarly to the COPY instruction but includes additional capabilities like unpacking compressed files and fetching remote resources. While versatile, caution should be exercised with ADD as it might lead to unexpected behaviours when dealing with URLs. For simpler file copying, COPY is generally preferred. Utilize ADD when the advanced features it offers are necessary, such as when dealing with compressed archives or web content retrieval.</p><p>The syntax for ADDis similar to COPY and follows similar use of wildcards. Additionally, remote paths like Git repositories and archive files can be provided as the source path.</p><h4>RUN</h4><p>The RUN Docker instruction is used to execute commands during the image build process. It allows you to install packages, configure settings, and perform various actions within the container. Each RUN instruction creates a new intermediate layer in the image, capturing the changes made by the command. This instruction is crucial for setting up the environment and dependencies required for the application to run correctly. It&#39;s important to minimize the number of RUN instructions to optimize image size and layer caching.</p><p>The syntax for RUN instruction is below:</p><pre>RUN &lt;command&gt;</pre><p>The <em>command</em> will be executed when the instruction is run. You can also provide the command in the exec format as shown below</p><pre>RUN [&quot;executable&quot;, &quot;param1&quot;, &quot;param2&quot;]</pre><p>Below is an example that used the RUN instruction to install the Redis package and then start the Redis server.</p><pre>docker build https://github.com/nitin-manju/DockerSamples.git#main:Redis</pre><p>The docker file for the same can be found <a href="https://github.com/nitin-manju/DockerSamples/blob/main/Redis/Dockerfile">here</a>.</p><h4>EXPOSE</h4><p>The EXPOSE Docker instruction documents the network ports that a container will listen on when it&#39;s running. It doesn&#39;t actually publish the ports; rather, it serves as a form of documentation for developers and operators. This information aids in understanding which ports the containerized application requires for proper functionality. When combined with the -p flag during runtime, EXPOSE helps map container ports to host machine ports for external access. While not mandatory, EXPOSE is particularly valuable in scenarios where multiple containers communicate or when deploying to orchestrated environments, ensuring efficient networking setup and inter-container communication.</p><pre>EXPOSE 80</pre><p>This will expose port 80 as a TCP (default) port. However, we can specify the protocol for the port.</p><pre>EXPOSE 80/udp</pre><p>Since this serves only as documentation for the developers, to actually apply the port mapping during runtime, use the -p flag during the docker run command. and the -P flag will publish all the exposed ports to random ports on the host system. See the example for the -p flag below.</p><pre>docker run -p 80:80/tcp ...</pre><p>An example Dockerfile that exposes a port is below.</p><pre>FROM alpine<br><br>RUN apk add --update redis<br><br>EXPOSE 6379<br><br>ENTRYPOINT [&quot;redis-server&quot;]</pre><h4>VOLUME</h4><p>The VOLUME Docker instruction designates a specific directory within a container as a volume, allowing data to persist beyond the container&#39;s lifecycle. This data can be shared between containers or with the host system. Decoupling data storage from the container, VOLUME supports data persistence, scalability, and data sharing across different containers.</p><p>An example to mount the logs directory is shown below.</p><pre>VOLUME [&quot;/logs&quot;]</pre><p>However, it’s worth noting that modern best practices often lean towards using named volumes or bind mounts for more controlled and manageable data storage, as these options offer better management and flexibility compared to the VOLUME instruction.</p><p>An example of a VOLUME is shown below</p><pre>FROM alpine<br><br>VOLUME /volume<br><br>CMD echo &quot;hello world&quot; &gt; /volume/message.txt</pre><p>When the image is built and executed, provide the host directory using the -v flag followed by the <em>&lt;host directory&gt;:&lt;container volume&gt;</em></p><pre>docker run -v /host-volume:/volume &lt;image-name&gt;</pre><p>Here in the above example, /host-volume is a directory on the host machine.</p><h4>ARG</h4><p>This instruction helps in declaring variables and parameters. This is particularly useful when you want to pass external values as build parameters. We can have multiple ARG instructions in a Dockerfile.</p><p>If the ARG is declared before the FROM, this parameter can be used in the FROM instruction. However, it can not be used after the FROM. To use it after the FROM, redeclare again but without any initialization value.</p><p>To pass a value during the build command, use the --build-arg flag for each ARG instruction.</p><p><strong>Example: Dockerfile ARG Instruction in action</strong></p><pre>ARG MESSAGE=HelloWorld<br><br>FROM alpine<br><br>ARG MESSAGE<br><br>RUN echo &quot;$MESSAGE&quot; &gt; file.txt<br><br>CMD cat file.txt</pre><p>Here in the above example, we see that we have an ARG instruction declaring a parameter MESSAGE before the FROM. We intend to use the value stored in it to be written into a file (file.txt) using the echo command. And finally, print the file content using the cat command.</p><p>Build this image with the parameter passed externally as an argument:</p><pre>docker build --build-arg MESSAGE=&quot;Hello World From External ARG&quot; .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_hV6MN7bVmJMH-gCOigcAw.png" /></figure><p>Run this image and you should see the below output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*0X7XW1MaLuJQaWcAEwlDBw.png" /></figure><p>ARG is multipurpose and is used in various scenarios during the docker image build process.</p><h4>ENV</h4><p>The ENV Docker instruction sets environment variables within a Docker image. These variables persist during image creation and can be utilized by subsequent commands or processes within the container. This instruction is valuable for configuring application-specific settings, such as database URLs or API keys.</p><p>ENV enhances containerization by promoting configuration separation from code, making the image more adaptable across environments. It also improves image maintainability by consolidating configuration in a single location, simplifying updates. However, sensitive data should be handled with care, and more secure methods like Docker secrets are recommended for sensitive information.</p><p>The syntax to define an ENV is as below</p><pre>ENV &lt;key&gt;=&lt;value&gt; ...</pre><p>You can set multiple key-value pairs within the same line separated by a space. This variable will persist even after the containers are run and can be overridden during the run time using --env &lt;key&gt;=&lt;value&gt;</p><p>In the <a href="https://medium.com/@nitinmanju/docker-105-building-a-multilayer-docker-image-70c086fcb672">next chapter</a>, we will build a Dockerfile with some of the instructions discussed above. Hope you have enjoyed this post. Stay tuned for more Docker 101!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64854c577cee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker 103 — Building an image using Dockerfile]]></title>
            <link>https://nitinmanju.medium.com/docker-103-building-an-image-using-dockerfile-caf99397fb48?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/caf99397fb48</guid>
            <category><![CDATA[docker-101]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Wed, 16 Aug 2023 19:32:32 GMT</pubDate>
            <atom:updated>2023-08-18T21:18:09.673Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker 103 — Building a simple image using Dockerfile</h3><p>In <a href="https://nitinmanju.medium.com/docker-101-cli-and-basic-commands-to-operate-containers-e6ce73a516d">Chapter 2</a>, we discussed a little about the Docker CLI and how we could create containers from images and manage them using the CLI. In this chapter, we will build our custom images and create containers from the images we build. This article is meant to make it easy to understand the Dockerfile and the build process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FIlbGfc5f_Nbcc-DXQkS_Q.png" /></figure><h3>Dockerfile basics</h3><p>To build our own Docker images, we need to instruct the Docker CLI on how to build it. To achieve this, we must create a specific file with all the instructions. It is called the <strong>Dockerfile. </strong>The Dockerfile is a text file with no extension of any sort. It is simply named “Dockerfile”.</p><p>Once we have this file created and set up, the docker CLI can then use this file as input to build images using the command docker build. The images can then be used to create containers as we have discussed <a href="https://nitinmanju.medium.com/docker-101-cli-and-basic-commands-to-operate-containers-e6ce73a516d">before</a>.</p><h4>Format of Dockerfile instructions</h4><p>Each line in the Dockerfile build instruction will look something like this:</p><pre>INSTRUCTION &lt;arguments&gt;</pre><p>The instruction is not case-sensitive and contains the Build command. The arguments will follow this instruction. Example FROM alpine</p><p>Every Dockerfile begins with a FROM instruction barring some exceptions which we will discuss later.</p><h4><strong>Adding comments in the Dockerfile</strong></h4><p>You can also add comments to the file using a # symbol. Example of a comment#This is a comment</p><p>Comments are removed from the execution during a preprocessing step before the builder instructions are executed.</p><p><strong>Example 1: A simple Dockerfile looks something like this:</strong></p><pre>#This is the Hello World Dockerfile</pre><pre>FROM alpine</pre><pre>CMD [&quot;echo&quot;, &quot;Hello World&quot;]</pre><p>Create this Dockerfile in a local directory and then build this into a Docker image using the command below:</p><pre>docker build .</pre><p>The CLI will search for a Dockerfile in the current directory because of the . (period) at the end of the command. If it finds a Dockerfile, it will build an image. Refer to the below log:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HT_nG32XdLdPrmvBk2hCQg.png" /><figcaption>Docker build command in action</figcaption></figure><p>Refer to the last line, the string is the ID we can use to refer to the image. Let&#39;s try to run a container using this ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PJe-97Iac4z1jF9OFrO3VA.png" /><figcaption>Output from Docker run command</figcaption></figure><p>You can see that the startup command has been executed and has printed the “Hello World” message on the console.</p><h3>Understanding the image build phase</h3><p>The build command requires a context to be set. The context can be a PATH which is a location on the local file system or a URL.</p><p>In the command, docker build . we provide the current directory as context using the . at the end of the command.</p><p>Typically, the Dockerfile is expected to be present in the build context root directory, however, if the Dockerfile is located somewhere else in the file system, the -f flag can be used to supply the location of the Dockerfile.</p><pre>docker build -f C:/path/to/a/Dockerfile .</pre><p>Using a remote Dockerfile is possible by passing a URL to a git repository.</p><pre>docker build https://github.com/nitin-manju/DockerSamples.git#main:HelloWorld</pre><p>Here the Dockerfile is recursively found and the git repository becomes the context. You could also specify the branch and the sub-folder in the repository.</p><p>Notice #main which specifies the main branch and :HelloWorld<strong> </strong>which specifies the sub-folder. This will checkout the git repository and set the subfolder as the build context.</p><h4>Layers in the build process</h4><p>The above Dockerfile example (1), has FROM alpine as the first instruction. Every Dockerfile will usually start with an instruction like FROM followed by the name of an image. Here, alpine is the name of an image, which is used as the base image, kind of like a base operating system on a computer. This image is based on the <a href="https://www.alpinelinux.org/">Alpine Linux</a> distribution and is officially maintained by <a href="https://hub.docker.com/_/alpine">Docker</a>. It uses <a href="https://docs.alpinelinux.org/user-handbook/0.1a/Working/apk.html">APK </a>as its package manager.</p><p>The next instruction that follows is CMD [&quot;echo&quot;, &quot;Hello World&quot;] where CMD is another instruction and [&quot;echo&quot;, &quot;Hello World&quot;] becomes the command.</p><p>The docker daemon runs the Dockerfile line by line. Hence committing the output of every step into a new image. Except for the very first step, every consecutive step will create a container instance using the image from the previous step and execute the instruction, resulting in a final image which becomes the output of the Dockerfile build process. These images in the intermediate steps are known as layers.</p><p>Let&#39;s create a more complex image. In the previous chapter, we used the Redis image to <a href="https://nitinmanju.medium.com/docker-101-cli-and-basic-commands-to-operate-containers-e6ce73a516d">create containers</a> using docker run redis. Let us try to create our own Redis image.</p><p><strong>Example 2: Multi-layer Dockerfile<br></strong>Paste the following lines into a Dockerfile and build it:</p><pre>FROM alpine</pre><pre>RUN apk add --update redis</pre><pre>CMD [&quot;redis-server&quot;]</pre><p>The output should look something like this after you build and create a container from the resulting image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*63geUBoCo9-6bNCTkzPXPA.png" /><figcaption>Docker build output</figcaption></figure><p>You notice that the container is running the redis-server command and is ready to accept new connections.</p><p>We will understand these instructions in detail in the <a href="https://nitinmanju.medium.com/docker-104-dockerfile-instructions-in-detail-64854c577cee">next chapter</a>. Hope you have enjoyed this post. Stay tuned for more Docker 101!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caf99397fb48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Run a Keycloak dev server instance on Azure in minutes]]></title>
            <link>https://nitinmanju.medium.com/run-a-keycloak-dev-server-instance-on-azure-in-minutes-da452cd6a928?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/da452cd6a928</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[app-service]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[identity-management]]></category>
            <category><![CDATA[keycloak]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Sat, 15 Jul 2023 18:23:29 GMT</pubDate>
            <atom:updated>2023-07-16T04:09:52.259Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLuEkB2SIsn01WJqd9rM9g.png" /></figure><p>Keycloak is a powerful open-source tool designed for managing user identities and access to applications. It offers a range of essential features, including secure authentication, authorization, and single sign-on convenience. With Keycloak, developers can quickly implement robust security measures and centralize user management across different platforms.</p><p>It supports multiple authentication methods, such as traditional username and password, as well as social logins and additional layers of security like multi-factor authentication. By providing a flexible architecture and seamless integration options, Keycloak simplifies the process of implementing reliable and secure identity management for modern applications.</p><p>It is easy to deploy a dev server instance of Keycloak on Azure for testing, follow on with the article to create a dev server instance running on Azure App Service with a few clicks.</p><h4>Create and configure a new Web App (Azure App Service):</h4><ol><li>Create a new <em>Web App</em> on Azure</li><li>Under ‘Basics’ settings, select the ‘Subscription’</li><li>Select an existing <em>Resource Group</em> of your choice or create new</li><li>Provide a name, (<em>eg. keycloak-devtest</em>) and note down the fully qualified domain name that has been created. It should be: <em>https://&lt;name&gt;.azurewebsites.net</em></li><li>Select ‘Docker Conatiner’ under publish</li><li>Choose ‘Linux’ as the operating system</li><li>Select the ‘Region’</li><li>Select the pricing plan, the free tier should work</li><li>Zone Redundancy can be disabled</li><li>Review the settings and click ‘Next’ and move on to Docker settings</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nkfbJzRB37e7o9EPC5u0-g.png" /></figure><h4>Configure Docker settings:</h4><ol><li>Select ‘Single Container’ under Options</li><li>Select ‘Docker Hub’ under Image Source</li><li>Select ‘Public’ under Access Type</li><li>Type <em>jboss/keycloak:latest</em> under Image and tag</li><li>Leave the startup command empty</li><li>Click on ‘Review + Create’ and then ‘Create’</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*CkRRJR6Et_nC5v8_rlxpXg.png" /></figure><p>After successful deployment, follow the below steps.</p><h4>Configure Application Settings:</h4><ol><li>Navigate to the resource by clicking on ‘Go to Resource’</li><li>Under Settings, click on ‘Configurations’</li><li>We have to add three new ‘Application settings’ as shown below (choose your own password)</li></ol><pre>KEYCLOAK_FRONTEND_URL : https://&lt;name&gt;.azurewebsites.net/auth<br>KEYCLOAK_USER : admin<br>KEYCLOAK_PASSWORD: admin</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHalS8xGPOvGn1zB0TE2DQ.png" /></figure><p>That should be it. Restart the Web App and wait for the container to boot up (Free tier takes more time). On successful boot, the container should be ready to accept new requests.</p><h4>View the deployment logs:</h4><p>To view the deployment and container logs, navigate to ‘Deployment Center’ and click on logs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vq8AwohzldN1RPevvhsZSg.png" /></figure><p><strong>Note 1</strong>: This is to be used as a dev server instance only. Do not use it for the production use case.</p><p><strong>Note 2</strong>: By default, Keycloak uses the H2 database in the dev-server instance, data will not be persisted after the container/web app is restarted.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da452cd6a928" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I asked ChatGPT to create a superhero comic]]></title>
            <link>https://nitinmanju.medium.com/i-asked-chatgpt-to-create-a-superhero-comic-2591aaebb303?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/2591aaebb303</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[superheroes]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Thu, 05 Jan 2023 14:58:05 GMT</pubDate>
            <atom:updated>2023-01-08T16:15:00.709Z</atom:updated>
            <content:encoded><![CDATA[<p>AI chatbot <a href="https://chat.openai.com/">ChatGPT</a> by OpenAI has taken the world by storm. Launched as a prototype on November 30, 2022, it quickly garnered attention and gained new users faster than any other service recently within a very short period.</p><p>This AI chatbot is easy to talk to and it improves vastly over time. Having access to a very large language model, ChatGPT is fine-tuned with <a href="https://en.wikipedia.org/wiki/Supervised_learning">supervised learning</a> as well as <a href="https://en.wikipedia.org/wiki/Reinforcement_learning">Reinforcement learning</a>.</p><p><em>AI is here to stay and here is why I think it will be the most sought technical skill set in the coming years.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xjPczWGV1HJMfUSibFYczw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@agk42?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Alex Knight</a> on <a href="https://unsplash.com/photos/2EJCSULRwC8?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I love <a href="https://en.wikipedia.org/wiki/Superhero">superheroes</a> and like reading comic books. Most movies based on comic book superhero characters turn out to be <a href="https://en.wikipedia.org/wiki/List_of_Marvel_Cinematic_Universe_films#Box_office_performance">blockbusters</a>, yet they are becoming monotonous. What if I could create my superhero? And what if I could create comic books based on this superhero?</p><p>Someone or something could help me with this project may be…</p><h4>I asked ChatGPT to create a superhero comic for me, here is what happened next…</h4><p>I start with a straightforward question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*ty5Uaj37UoImkK4gEdETFw.png" /></figure><p>Then I make a mistake, yet it understands me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*HGX82A-acuDPjnyO8kA31w.png" /></figure><p>I give one-word answers, but it doesn&#39;t mind!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*vWH8DTYZSCjgXzf8A2CzDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*mvqJRDs3sD68KFjfrxWuKw.png" /></figure><p>“<em>Vajra</em>” What a great name for a superhero.</p><p>After writing some good stuff, it asks me for more suggestions! Nice!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*ZWv5skLD2qNR9EcfGktLhQ.png" /></figure><p>It starts writing the story for me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*kDL4m1KhwHzsrbn2xPWZKg.png" /></figure><p>And it continues….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*j9YoT6EfzUqAm8fFeGWXtQ.png" /></figure><p>I asked it to create a comic out of the story it just wrote. Here is the exciting part... I have no experience creating comics, but I got an excellent description of what the comic panels should look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*xlXcZ48QZC4WQBHJBCj4sQ.png" /></figure><p>Some more…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*DkGeFnfp1UFVABbUd9Ttxg.png" /></figure><p>I ask it to draw the panels. But it does something better by describing each of the panels with more detail, leaving it to my imagination to draw them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*OTh9i_s4yhafnq2WNEiV5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*IMUITqyfgddQUIQ6hIxvzg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*jAwWzXY5DSTenRzntO2K1A.png" /></figure><p>I decided to ask a bit more in-depth questions about the character <em>Vajra</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*xlSn3OKDtzmqitylvod6zQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*KIR8E5o0OW3_PIPNzGYUlQ.png" /></figure><p>And finally, I thank ChatGPT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*4Bw5vE0-q-o09KNnesStYQ.png" /></figure><h4>Let’s see what happened here</h4><p>I asked ChatGPT to create a superhero comic for me, it began by giving a few suggestions for creating a backstory for the character. It then took a few suggestions and ultimately a story was created and the comic panels were also described in detail. It also considered adapting this superhero to a particular region instead of assuming one and then attaching the regional elements to the story.</p><p>It was a very human-like interaction because I didn&#39;t have to adapt to the machine, rather the machine adapted to me. For someone like me who has never created a superhero comic, this was very helpful and gave me a baseline to start my comic book project.</p><p><strong>This tells me a few things about ChatGPT and why it will be big:</strong></p><ol><li>It can have very close to human-like conversations</li><li>It can hold and remember the whole conversation (I could go back to a previous interaction and refer to it)</li><li>It will ask for suggestions and can adapt to changes</li><li>It can fine-tune the result to make it better</li><li>It is super easy and simple to use</li></ol><p>The way it works today is fascinating and it will only improve over time. However, not everything is good, it can sometimes produce results that seem correct but are not so.</p><p>Also, we should consider the training model, what may be acceptable today in society may not be so tomorrow, and ChatGPT results need to adapt to these changes. Only time will tell how efficient it will be in the future.</p><p>But, the real question is: Is <a href="https://en.wikipedia.org/wiki/Skynet_(Terminator)">Skynet</a> going to be real someday?</p><p>Let’s ask ChatGPT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*Q3RtKj1_ZVKipi4gzsSrFw.png" /></figure><p>But of course! that is what Skynet would want me to think, Rightttt?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*rABHkMmphrCoCsArF2XPZQ.png" /></figure><p>Well, it looks like it&#39;s not Skynet(yet). So rest assured!</p><h4>Conclusion</h4><p>AI and Robots may not take over the world anytime soon, however, people who understand AI and AI-powered tools will be the most sought technically skilled resources in the coming years. The human brain is limited to only holding a certain level of detail at a time, however, with AI tools, people could access vast information in record time, which will certainly help them to make quicker decisions (also making us dumber over time, hehe..).</p><p>Today, AI is used by every major technology company and will only grow further with time. If you are interested in understanding AI and what it is all about, here is a free course by <em>Andrew Ng</em>: <a href="https://in.coursera.org/learn/ai-for-everyone">AI for everyone</a>.</p><p>Cheers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2591aaebb303" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Going Serverless with Azure Static Web Apps and Functions for Production ready Scalable Web…]]></title>
            <link>https://nitinmanju.medium.com/going-serverless-with-azure-static-web-apps-and-functions-for-scalable-web-applications-ca6b504d1716?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca6b504d1716</guid>
            <category><![CDATA[serverless-architecture]]></category>
            <category><![CDATA[azure-services]]></category>
            <category><![CDATA[azure-static-web-app]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[azure-functions]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 20:32:55 GMT</pubDate>
            <atom:updated>2022-09-14T09:34:19.933Z</atom:updated>
            <content:encoded><![CDATA[<h3>Going Serverless with Azure Static Web Apps and Functions for Production ready Scalable Web Applications</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MAG9gAxKhktOzXg17-iphA.jpeg" /><figcaption>Photo by Manuel Geissinger: <a href="https://www.pexels.com/photo/black-server-racks-on-a-room-325229/">https://www.pexels.com/photo/black-server-racks-on-a-room-325229/</a></figcaption></figure><p>With web frameworks like Angular and React gaining traction every day, it has become easier to develop robust and secure web applications and single-page applications that typically connect to a backend API to get its data or perform the business logic. However, maintaining these applications using traditional servers is cost-intensive and cumbersome, especially with high availability and low latency business cases.</p><h3>What is Serverless?</h3><p>Serverless is a <a href="https://www.redhat.com/en/topics/cloud-native-apps">cloud-native</a> development model that allows developers to build and run applications without having to manage servers.</p><p><a href="https://azure.microsoft.com/en-in/solutions/serverless/#overview">Microsoft Azure</a> provides services to build, deploy and operate serverless apps on an end-to-end platform to:</p><ol><li>Increase developer velocity by reducing the time spent on tasks that are non-core to the business</li><li>Improve team agility and performance by using a fully managed platform to build, deploy and operate applications</li><li>Improve organisational impact by accelerating time to market</li></ol><p>We will today discuss one such service provided by Azure called Azure Static Web App.</p><h4>What are static web applications?</h4><p>Static web applications simply put, are web applications with files and assets that do not require server-side rendering. These files can be served as static assets via application server or a distribution service like CDN. Examples include HTML, CSS, JavaScript and Image files. It is important because these static files do not change dynamically per request or require any preprocessing on the server side and are processed only on the web browser.</p><h4>How are they different from server-side rendered applications?</h4><p>With server-side rendered web applications, the page is rendered on the application server using technologies like PHP, ASP or JSP and is then a processed HTML response is returned to the web browser. This requires the web server to perform the rendering and preprocessing of the pages which typically involves application business logic. However it has to be noted that, such type of applications can also have some static resources. Hence they are a combination of static resources and server side rendered pages.</p><h3>Azure Static Web Apps</h3><p>Traditionally these front-end web applications are served using single or multiple servers with a load balancer managing the server load.</p><p>Having a geographically distributed web application is expensive when serving them using the traditional methodology involving multiple application servers and load balancers.</p><p>This is where <a href="https://docs.microsoft.com/en-us/azure/static-web-apps/overview">Azure Static Web Apps</a> can help you with a fully managed global distribution of static content to significantly reduce latency and increase throughput for global users. The static application is served faster as its closer to the user geographically.</p><blockquote>Azure Static Web Apps can also reduce the deployment and maintenance time and efforts.</blockquote><h4>A typical development workflow of a web application:</h4><ol><li>A source code version control system like Git is used to safe-keep and version control the application code</li><li>A developer will push application code to this repository</li><li>A Continuous Integration (CI) system builds applications from the source code</li><li>A Continuous Deployment (CD) system will push the application build to the application server</li></ol><p>With Azure Static Web Apps, steps 3 and 4 are combined and the developer doesn&#39;t have to take care of the CI and CD of the application, Azure will.</p><h4>Application development workflow with Azure Static Web Apps:</h4><ol><li>A source code version control like GitHub or Azure DevOps is used to keep the application code</li><li>The Azure Static Web App is configured to watch the code on a preferred branch of the code repository for any new changes</li><li>When new code is pushed, the code is built and deployed to a geographically distributed CDN-like delivery network.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gxz9pqwJVwLbFS0KKvf9qQ.png" /><figcaption>Flow: From code to application delivery</figcaption></figure><h3>Let us try to build our own static web application using Angular and Node and deploy on Azure Static Web Apps</h3><p><strong>Prerequisites:</strong> In this demo, we will be using <strong>Angular </strong>to build a sample front-end application. We will use<strong> NodeJS </strong>to create an API application using <strong>Azure Functions</strong>. We will be using <strong>GitHub </strong>as the source code repository. You will also need an <strong>Azure account </strong>with an<strong> Azure subscription</strong>. You can try it for free <a href="https://azure.microsoft.com/en-us/free/">here</a>.</p><blockquote>The code used in this demo is available on GitHub <a href="https://github.com/nitin-manju/AzureSamples">here</a>. Feel free to fork it to save time.</blockquote><p>Let&#39;s get started!</p><h4><strong>Create a new GitHub repository</strong></h4><p>If you do not have a <a href="https://github.com/">GitHub </a>account, create one first. Then, create a new repository. Follow the instructions provided <a href="https://docs.github.com/en/get-started/quickstart/create-a-repo">here </a>if you need help.</p><p>Clone this repository on your local machine, you will have to link your GitHub account with the local development machine to work with GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*dznRY2hzaypWIwLuXkue-A.png" /></figure><p>Next, navigate to this cloned directory. I have created a subfolder called <em>StaticWebApps </em>however this is not mandatory</p><h4><strong>Create an Angular application</strong></h4><p>If you are familiar with Angular development, then you are right at home. If not, you will get all the required information to get started from the <a href="https://angular.io/guide/setup-local">angular website</a>.</p><p>I have created an application <em>web-angular </em>as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zjfgD9LFF07cxC6SoXChA.png" /></figure><p>The ‘dist’ folder is not created by default unless we run npm run buildIf you run the app locally using ng serve the application should look something like this and we won&#39;t be making a lot of changes to the application just yet. The application is typically served at <a href="http://localhost4200/">http://localhost4200</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*umDvgMarlAmcjflhprSLOw.png" /></figure><p><strong>Commit this code to the main branch and then push it to the repository.</strong></p><p>The code should be visible in your GitHub repository now.</p><h4><strong>Create a new Azure Static Web App</strong></h4><p>Login into the Azure portal at <a href="https://portal.azure.com/">https://portal.azure.com</a></p><p>Create a new Resource Group (eg. AzureSamples)</p><p>Now create a new Static Web App (search for Static Web App) as shown below and fill in the below details.</p><p>Choose Plan type as ‘Free’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KC_8-TYW3zlCKL3bzAg_PQ.png" /></figure><p>Next, select a region for ‘Azure Functions API and staging details’ as shown below.</p><p>Select Deployment ‘Source’ as GitHub and connect it to your ‘GitHub account’ as shown below.</p><p>Select the ‘Organization’, ‘Repository’ which you created before and the ‘Branch’ (usually, the ‘main’ branch is selected for production deployments) These should be populated automatically and you will only have to select the right one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*f-0Zo_0ATvA1gpJ7XcQ_IA.png" /></figure><p>Now select the Build Presets as ‘Angular’</p><p>Give the ‘App location’ as per your folder structure. Since I have created a subfolder within my cloned directory, I have provided the same.</p><p>Leave the ‘Api location’ blank for now. We will come back to it later.</p><p>Provide the ‘Output location’ dist/&lt;app-name&gt; as shown below. The app name may vary based on how you named your angular application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*Awx36SkPnsN5YcZnrjU1Rw.png" /></figure><p>Click on ‘Review + create’ and the app should get deployed after a few seconds.</p><p>Go to the resource group and view the Static Web App, you should see a couple of details in the overview.</p><p>The URL is the URL where the web app will be hosted, you should also see the source which is the ‘main’ branch in our GitHub repository.</p><p>The deployment history gives information on the deployment runs that have happened through GitHub actions.</p><p>Click on the link and it will give you the information and history. The Workflow file can be viewed in your GitHub repository and can also be modified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*80ZfsP-V8M4SOIAnYxPBJA.png" /></figure><p>Let us make a small change to the Angular app and push the changes. This should reflect back on the deployment soon after the code is committed.</p><p>I am going to make one tiny change to the title of the application as shown below and then push the change to the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mqnWUEjXAaI4VGRItfAvsQ.png" /></figure><p>You will see that a new Workflow run has kicked in and should be complete in a few mins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Vq-o0gt01gPYDadnTyFzA.png" /></figure><p>Once completed, refresh the application URL to notice the change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zaA6aZ56zMZ8VQD0vLpoYg.png" /></figure><p>That is how simple it is to push new changes and deploy them to production!</p><h4>Let us create an API using Azure Functions and Node</h4><p>Now that we have our front-end up and running, let us create a simple API. Typically, applications get their data from an API. Let’s try to do the same in our sample application.</p><p><a href="https://azure.microsoft.com/en-in/services/functions/">Azure Function</a> is a serverless service provided by Azure, using which we can execute event-triggered business logic, run background jobs at timely intervals and create simple API endpoints without a complex setup.</p><p>Let us create a function, follow the below steps:</p><ol><li>Download and install the Azure Function Core Tools from <a href="https://github.com/Azure/azure-functions-core-tools">here</a>.</li><li>Navigate to the root folder of your project (the parent folder of the angular application).</li><li>Run the below command:</li></ol><pre>func init api --language javascript</pre><p>Use runtime as ‘node’ and language as ‘javascript’</p><p>Once the project is created, you should notice a folder called ‘api’ has been created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k5_bwYlPgFNxI5OTU8KfUQ.png" /></figure><p>Now let&#39;s create a new function. Run the below command:</p><pre>cd api</pre><p>once inside the API folder, run:</p><pre>func new --name message --template &quot;HTTP trigger&quot; --authlevel &quot;anonymous&quot;</pre><p>Use runtime as ‘node’ and language as ‘javascript’</p><p>The content of the folder should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*50Xjuy3eoBUd6j7ewLdVCg.png" /></figure><p>Replace the code inside the <a href="https://github.com/nitin-manju/AzureSamples/blob/main/StaticWebApps/api/message/index.js"><strong>message/index.js</strong></a> file with the following:</p><pre>module.exports = async function (context, req) {<br>   context.res.json({text: &quot;Hello from the Function API&quot;});<br>};</pre><p>Let’s run this function locally using the command:</p><pre>func start</pre><p>The output should look something like this, notice the URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*8phLe2Idehh2k1-vQM_9Ng.png" /></figure><p>If your type in this URL on your browser, you should see the result as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*x5t89bOvL0OQV17biuTvtg.png" /></figure><p>We have successfully created a function app! We have to make a change in our angular application to call this API.</p><p>I have deleted most of the code from the page <a href="https://github.com/nitin-manju/AzureSamples/blob/main/StaticWebApps/web-angular/src/app/app.component.html"><strong>app.component.html</strong></a><strong> </strong>and made one change as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g0i1StFXPPHn-9r_gK2hnw.png" /></figure><p>Replace the code in <a href="https://github.com/nitin-manju/AzureSamples/blob/main/StaticWebApps/web-angular/src/app/app.component.ts"><strong>app.component.ts</strong></a> with the below code:</p><pre>import { Component } from &#39;@angular/core&#39;;</pre><pre>@Component({<br>  selector: &#39;app-root&#39;,<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrls: [&#39;./app.component.css&#39;]<br>})</pre><pre>export class AppComponent {<br>  apiResult = &quot;...&quot;;</pre><pre>  constructor(){<br>    this.callApi();<br>  }</pre><pre>  async callApi(){<br>    var result =  await (await fetch(`/api/message`)).json();<br>    this.apiResult = result.text;<br>  }<br>}</pre><p>Save the code.</p><p>Edit the GitHub workflow file found under <strong>.github/workflows/azure-static-web-apps-&lt;DEFAULT-HOSTNAME&gt;.yml<em> </em></strong>and update the<strong><em> </em></strong>api_location to the API folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G2vsUkUscYiHGk9oCxlsxg.png" /><figcaption>Workflow file changes</figcaption></figure><p>Save the file. Push the changes to the repository.</p><p>The GitHub action should kick in and the changes should get deployed to the static web app. Once the deployment has been completed, refresh the URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bcW5GYwQ08BRBFfGzlPlVA.png" /><figcaption>API communication has been established</figcaption></figure><p>The API works and the front-end is able to connect and receive data from the API. We can further extend the API to connect to a database to meet our business requirements. However, it is out of the scope of this exercise.</p><h3>Conclusion</h3><p>We have created a serverless solution that can host both the front-end and an API using Azure Static Web App. This solution is simple to manage as we don&#39;t have to maintain complex server configurations or deployments. To know more about Static Web Apps, read the documentation available <a href="https://docs.microsoft.com/en-us/azure/static-web-apps/">here</a>.</p><p>The code used in the above exercise is available in my GitHub repository which can be found <a href="https://github.com/nitin-manju/AzureSamples">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca6b504d1716" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker 101 — CLI and Basic commands to operate containers]]></title>
            <link>https://nitinmanju.medium.com/docker-101-cli-and-basic-commands-to-operate-containers-e6ce73a516d?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6ce73a516d</guid>
            <category><![CDATA[docker-command]]></category>
            <category><![CDATA[basic-docker-command]]></category>
            <category><![CDATA[docker-cli]]></category>
            <category><![CDATA[docker-101]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Tue, 06 Sep 2022 18:59:40 GMT</pubDate>
            <atom:updated>2023-08-18T07:45:23.219Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker 102 — Basic commands to operate containers using CLI</h3><p>In <a href="https://nitinmanju.medium.com/docker-101-a-beginners-guide-towards-docker-55ffe0994f95">Chapter 1</a>, we understood what Docker is and how it works in a nutshell. We have also installed Docker and are ready to move further. In this chapter, we will understand the basics of the Docker CLI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WWPFWok4-HxN8p2tmmTGCA.jpeg" /></figure><h4>The Docker CLI</h4><p>The Docker CLI is a tool with which you control various Docker components. It is the primary way to interact with Docker. The CLI sends out the command to the daemon which in turn carries out the task.</p><p>Let&#39;s get started with some basic commands to create, run and operate the containers.</p><h4>docker run</h4><p>The very first command we will understand is the run. This command will create a container from an image and start it. It will execute the default operation (startup command) that has been configured for the image. However, this can be overridden to run a custom command.</p><p>Refer to the below syntax:</p><pre>docker run &lt;image name&gt; [Command]</pre><p>Alright, let’s get started. As a real programmer would do, the first thing we do is say hello to the world. Assuming the installation went well and without errors, let’s run our first docker command. Open a terminal/command window and try:</p><pre>docker run hello-world</pre><p>This should download and run the ‘hello-world’ image as a container.</p><p>The first time you run it, the image is not found in the local repository, hence Docker will pull it from the DockerHub repository and then create the container from the image. Notice the first few messages after the command is executed. Refer to the below image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*zPTU52Q27M2ySEdq6EVgGg.png" /></figure><p>If we run the same command a second time, notice what happens:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*zksyWCusc48GsB8jQNdRug.png" /></figure><p>This time it didn&#39;t pull the image since it was available locally.</p><p>Let us try to run some overridden commands. If you notice above, the hello-world image when executed will output a series of text. This is because it executes a startup command that does it for us. However, sometimes, we may have to execute additional commands.</p><p>To demonstrate this, we will use a different image. We will use an image called ‘<a href="https://hub.docker.com/_/busybox/">busybox’ </a>which is a lightweight Linux image from the Docker community. Try:</p><pre>docker run busybox echo hello world</pre><p>we see that the image name is followed by the custom command echo followed by “hello world”</p><p>echo is a Linux tool to echo the text back to the standard output. In our case, we want to echo “hello world”. The output should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*lh4djviG1x3Y8yUZGhb_QA.png" /></figure><p>You can use some other commands which are supported by Busybox like ls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*koDxVtMEY06xRlKpcu8YLg.png" /></figure><p>You must have noticed that running the commands will immediately exit the container after the startup command is done executing and the prompt is returned to us.</p><p>However, it is possible that a container will continue to run and doesn&#39;t exit until we explicitly do so. For example, the ‘Redis’ image will run as a container and continue to do so until explicitly stopped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7VyT55ssGP19tzScVVlqhw.png" /></figure><p>You can see that the prompt has not been returned to us.</p><h4>docker ps</h4><p>This brings us to the next topic, the ps command. Similar to its use in other contexts, the ps command will return a list of running container processes. Try:</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CsxAI4XclSeTzcBqF-cKJA.png" /></figure><p>you will notice that it has listed the redis container process running, which we started in the previous exercise. Let us create another container:</p><pre>docker run busybox ping www.google.com</pre><p>If we now run the pscommand, we should see the below result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkLzINJlUgNPqEsDNpXIeg.png" /></figure><p>One thing to notice here is the ‘CONTAINER ID’ and the ‘NAMES’ column. These are useful to identify the containers for use elsewhere. Specifically, the ID is used to reference a running container. To get a history of all the containers created on your machine, use the --all flag.</p><pre>docker ps --all</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D7uoL1txCmTIIXAlv9P2Fw.png" /></figure><p>Notice the ‘CREATED’ and the ‘STATUS’ columns which give some information about the status of the container.</p><h4>docker create</h4><p>If you are wondering about the CONTAINER ID which was created and is displayed when the ps command is executed, we will talk about it next. The run command is a combination of two instructions.</p><blockquote>Run = Create + Start</blockquote><p>The create command will create a container instance from an image, which is when a container ID is also created.</p><pre>docker create &lt;image name&gt;</pre><p>Let us try to create a container from the Redis image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*Fs99NvBavBv8TCpP4T9dtA.png" /></figure><p>This command returns a long string, which is the ID. If you are wondering the ps command hadn’t returned a long string like this, then you are right we can identify a container using the first few characters from this ID. We can now start this container using the start command discussed next.</p><h4>docker start</h4><p>The start command is used to start a created container.</p><p>Copy a few characters from the container ID which was generated and use it in the start command. You can use the full ID as well.</p><pre>docker start &lt;container ID&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*-KqfTDiOZjYXUqDouTSQbg.png" /></figure><p>To verify if the container has started, use the ps command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*FjxGXtyoitIxs_r_RZR-9g.png" /></figure><p>using the -a flag along with the start command will also print the output from the container. Use it as shown below:</p><pre>docker start -a &lt;container ID&gt;</pre><h4>docker logs</h4><p>When containers are started, they may print certain output logs. The logs command can be used to get this log from the container.</p><pre>docker logs &lt;container ID&gt;</pre><p>Let us create and start a container and then execute logs. You will notice that, when we start the container, we see no output. However, we can get it back using this command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ExEk-PFfyESAUMx_uIelw.png" /></figure><p>It should be noted that when the logs command is executed, it will not restart the container.</p><h4>docker exec</h4><p>We can execute commands inside a running container. This is handy when you would like to execute additional commands after the default command configured for the image is done executing.</p><p>To do so, we can use the exec command. This along with the -i and -t flags will open a channel to execute commands inside the container. Refer to the command below:</p><pre>docker exec [-it] &lt;container ID&gt; &lt;command&gt;</pre><p>You can even open a shell prompt from inside the running container using the sh as the command for exec. This will allow you to execute more than one command. Refer below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6YdIpA1qm4iLFGltl-Bjg.png" /></figure><p>you could now type supported shell commands like ls in the prompt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0zhm4ulZHtGXEFu7EZRrQ.png" /></figure><p>If you don&#39;t attach the -it flag, the command will be executed, however, you won&#39;t be able to interact with the standard input to the container.</p><p>The -it flag can be used along with the run command while running containers. However, doing that the default command won&#39;t be executed.</p><h4>docker stop</h4><p>To stop a running container use the stop command. Pass the ID of a running container and it should be stopped.</p><pre>docker stop &lt;container ID&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*MmyrghN84G2LOlkn93hKew.png" /></figure><p>verify by running the ps command to make sure the container has stopped.</p><p>Restarting a container is possible by executing the start command with the same container ID. Using the --all flag should give a list of stopped containers.</p><p>The stop command will gracefully shut down the container process. It gives enough time to the container to perform any action that should be part of the shutdown process. If the stop command doesn’t respond on time, docker will fall back to a different command called kill which is explained next.</p><h4>docker kill</h4><p>Using the kill command will kill the container <strong>immediately </strong>and won&#39;t give any time for the shutdown process.</p><pre>docker kill &lt;container ID&gt;</pre><h4>docker system prune</h4><p>Creating containers will take up system resources, if not handled correctly, it can take up a lot of storage space. To clean up stopped containers and all the associated resources, use the system prune command. Try:</p><pre>docker system prune</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwthlL-Usap3Q5easUm5KQ.png" /></figure><p>This will reclaim some of the system resources and delete unused containers. However, it should be noted that the local images downloaded from the Hub will also be deleted.</p><p>In the next <a href="https://medium.com/@nitinmanju/docker-103-building-an-image-using-dockerfile-caf99397fb48">chapter</a>, we will learn how to build our first image using a Dockerfile. Hope you have enjoyed this post. Stay tuned for more Docker 101!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6ce73a516d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[De-clutter namespaces in C# 10]]></title>
            <link>https://nitinmanju.medium.com/de-clutter-namespaces-using-c-10-60822af79336?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/60822af79336</guid>
            <category><![CDATA[namespaces]]></category>
            <category><![CDATA[dot-net-developers]]></category>
            <category><![CDATA[charp10]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[dotnet]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Mon, 30 May 2022 12:55:11 GMT</pubDate>
            <atom:updated>2022-09-12T09:12:46.548Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guDewWoB-FvLDDcokL4-gw.jpeg" /><figcaption>Photo by Mohammad Rahmani on Unsplash</figcaption></figure><p>C# 10 was released last year and it has introduced a host of new features. Below is a list of useful features specifically designed around the declarations of namespace that can help you tidy your code base.</p><h3>Global namespaces</h3><p>If you have a large code base, chances are, the file is already cluttered with using statements. C# 10 introduces global namespaces, which like the name suggests, can be declared globally and will be available across all the files in your project. The <a href="https://teams.microsoft.com/l/channel/19%3a6Df8uermnHupxEUZZT659OnGHglmslwV9G-mLy_eQt01%40thread.tacv2/General?groupId=e3ee3b61-53d9-4616-b0b7-368d740cfae8&amp;tenantId=bf7cb870-b378-42ab-a618-31704bc2e9b7"><em>global</em></a><em> </em>modifier is used to achieve this as shown below:</p><p>global using &lt;fully-qualified-namespace&gt;;</p><p>example: global using System.Configuration;</p><p>Typically, you would declare all the global namespaces in a single file like <strong><em>GlobalUsings.cs</em></strong> and that should allow you to use the namespaces in each file within the project without explicitly writing the using statements.</p><h3>Implicit namespaces</h3><p>C# 10 allows you to clean up ‘using &lt;namespace&gt;’ statements even further with implicit namespaces. When enabled, you don’t have to write the ‘<em>using &lt;namespace&gt;’</em> statement for commonly used namespaces like <strong><em>System, System.IO</em> etc </strong>as they will be referred to implicitly in all the files within the project.</p><p>When combined with global namespaces, it will further reduce the number of ‘<em>using &lt;namespace&gt;’</em> statements required in a C# file since the commonly used namespaces don’t have to be declared globally. <strong>However, it is <em>not</em> mandatory to combine them together</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*D_ybgXhmTPGFdFVh0X-riA.png" /></figure><p>This feature should be enabled by default for projects created using Visual Studio 2022 and .NET 6. However, to achieve this manually add the property ImplicitUsings and set it to <em>enable </em>in the project properties as shown below.</p><pre>&lt;PropertyGroup&gt;<br>    &lt;!-- Other properties like OutputType and TargetFramework --&gt;<br>    &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;<br>&lt;/PropertyGroup&gt;</pre><h3>File-scoped namespaces</h3><p>C# 10 allows you to create namespaces inside a file in a declarative manner. A namespace declaration can simply be written as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*N4bAHTI5_SE1F4eSGv9gIQ.png" /></figure><p>Notice the ‘;’ after the namespace and the missing curly bracket enclosure. The code inside this file will be part of the declared namespace and this new namespace can be referred to in other C# files or globally.</p><h3>Bonus: Sync Namespaces</h3><p>This is a new Visual Studio 2022 feature and is not tied with C# 10.</p><p><strong><em>Sync Namespaces </em></strong>should work on earlier versions of .NET and C#. Right Click on the Solution or Project File and you should find it as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*7VGwHSGCj6HPaIIKuJlQCg.png" /></figure><p>If you have C# files which have been moved between folders and the namespaces are out of sync, this feature should come in handy to set the right namespace for each file based on the <em>&lt;ProjectName&gt;.&lt;FolderName&gt;</em> format.</p><p>This will especially come in handy when you are performing a migration of a legacy code base.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60822af79336" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker 101 — A beginners guide towards  Docker]]></title>
            <link>https://nitinmanju.medium.com/docker-101-a-beginners-guide-towards-docker-55ffe0994f95?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/55ffe0994f95</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[understanding-docker]]></category>
            <category><![CDATA[docker-architecture]]></category>
            <category><![CDATA[docker-101]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Thu, 14 Apr 2022 12:10:30 GMT</pubDate>
            <atom:updated>2022-09-11T08:38:35.892Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker 101 — A beginners guide towards understanding Docker</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*Fsl4KUGEw1d_YhrcxmLD-Q.png" /><figcaption><a href="https://www.networkworld.com/article/2942838/docker-the-container-company-with-a-whale-of-a-logo-adopted-a-real-whale.html">https://www.networkworld.com/article/2942838/docker-the-container-company-with-a-whale-of-a-logo-adopted-a-real-whale.html</a></figcaption></figure><p><strong>A</strong>s a developer, you must have experienced at least once where your app works great on your local/development machine but fails to work on the production?</p><p>Pulling your hair out of frustration, have you ever thought of shipping your development machine to production? This is where Docker will help you.</p><p>Well, Docker doesn&#39;t ship your development machine to production, no! But what it does is, enables you to separate your applications from your infrastructure so you can deliver software quickly. Docker makes it very easy to distribute and install software on a computer environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*w9QUMHadCjF3uSnP9qMcsw.png" /></figure><blockquote>Docker is an open platform for developing, <em>shipping</em>, and running applications</blockquote><h3>Understanding the underlying technology behind the Docker platform</h3><p><a href="https://docs.docker.com/get-started/overview/#the-docker-platform"><strong><em>Docker platform</em></strong></a> provides the ability to package and run an application in a loosely isolated environment called a container. A <a href="https://www.docker.com/resources/what-container"><strong><em>container </em></strong></a>is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host.</p><blockquote>Docker provides tooling and a platform to manage the lifecycle of your containers.</blockquote><p>Docker makes use of a technology called <a href="https://man7.org/linux/man-pages/man7/namespaces.7.html"><strong><em>namespaces </em></strong></a>to provide the isolated workspace(containers). When you run a container, Docker creates a set of <em>namespaces</em> for that container. These namespaces provide a layer of isolation. Each aspect of a container runs in a separate namespace and its access is limited to that namespace. The isolation and security allow you to run many containers simultaneously on a given host.</p><p>However, to run a container on a host, the container should be created first. This is where <strong><em>Docker Images </em></strong>show up. A Docker image is a read-only binary file that includes all of the instructions for creating a Docker container. Docker containers only have access to resources defined in the image. Think of it as a blueprint of a model of a car produced in a factory. The blueprint (image) can be used to produce cars (containers) by the factory (Docker) but will be limited to the design in the blueprint.</p><blockquote>A container is a runnable instance of an image and, often an image can be based on another image</blockquote><h4>Let’s talk more about containers</h4><p>To discuss containers, we need to first understand the basics of how an Operating System works. Most operating systems have something called a kernel which is a process that governs access to all the software running on the computer and the hardware resources connected to the computer. The kernel acts as this intermediate layer that manages the communication between the software running on the machine and the hardware connected to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*4zPSSas-_MuB4dLoUzGt9w.png" /></figure><p>If you take a look at the drawing above, you will notice that software like Chrome or Spotify is making system calls to the kernel which in turn is making the necessary low-level interactions with the hardware resources. They do not have direct access to the resources and have to go through the intermediate layer that abstracts the underlying hardware by exposing endpoints for the software to make the system calls. We had previously discussed the concept of <strong><em>namespaces</em></strong>. With Linux namespaces, we are allowed to isolate resources (eg. hardware resources like the hard drive ) per-process level. This is not essentially only for hardware but also the system software elements as well.</p><p>Another important concept that is very close to the namespace is the <strong><em>Control Groups</em></strong>(cggroups). This is a Linux kernel feature that allows you to allocate resources — such as CPU time, system memory, network bandwidth, or combinations of these resources — among user-defined groups of tasks (processes) running on a system.</p><p>With these two two kernel features, we can effectively govern and limit the access to resources per process. Hence a container can be defined as a process or a set of processes that are grouped together in such a way that they have access to a segment of resources (both hardware and software) specifically allocated to it hence effectively isolating it from the other processes and also other containers running on the same operating system.</p><h4>Docker Architecture</h4><p>The Docker platform is built on client-server architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fLB6C2XwFB2Fj8ag3UCi6A.png" /><figcaption>Docker Architecture</figcaption></figure><p>The <strong><em>Docker client</em></strong>(a CLI process running on the host machine) will communicate with the <strong><em>Docker host</em></strong> which contains a <strong><em>daemon </em></strong>process. This daemon does all the work of building and running the containers, managing the images, and all the necessary tasks to efficiently run the Docker system.</p><p>The client can run on the same machine which has the daemon(server) or it can also communicate with a remote daemon. The communication is established using REST API, Unix Sockets, or a network interface. The client can communicate with more than one daemon as well.</p><p>In the previous sections, we talked about images. It has to be noted that the images created by you can be used by other developers. This is one of the most useful features of the Docker platform. To distribute your images you need a central repository. A <strong><em>Docker Registry</em></strong> is a central repository to store docker images. You can create your own private registry or use a public registry like the <a href="https://hub.docker.com/">Docker Hub</a> which is configured by default on the Docker platform after installation.</p><h3>Installing Docker on your machine</h3><p>With a basic understanding of how Docker works, we are ready to install it on our machine. Depending on the OS, the installation of the Docker platform may vary a little. The docker desktop software is available only for Windows and Mac as of writing this article however is it not necessary to have it on the machine to have docker working.</p><p>To install Docker on <strong>Windows</strong>, follow the steps mentioned here: <a href="https://docs.docker.com/docker-for-windows/install/">https://docs.docker.com/docker-for-windows/install/</a></p><p>To install Docker on <strong>Ubuntu</strong>, follow the steps mentioned here: <a href="https://docs.docker.com/engine/install/ubuntu/">https://docs.docker.com/engine/install/ubuntu/</a></p><p>To install on other supported <strong>Linux </strong>distributions, follow the instructions found here: <a href="https://docs.docker.com/engine/install/">https://docs.docker.com/engine/install/</a></p><p>To install Docker on <strong>Mac</strong>, follow the steps mentioned here: <a href="https://docs.docker.com/docker-for-mac/install/">https://docs.docker.com/docker-for-mac/install/</a></p><p>You may also want to install a code editor like Visual Studio Code. This will ease up our development process. One additional benefit of installing Visual Studio Code on your machine is the extension support. Microsoft has developed a very useful Docker extension for VS Code that can come in handy. Download and install it from here <a href="https://code.visualstudio.com/">https://code.visualstudio.com/</a></p><h3>Next step…</h3><p>See you in the <a href="https://nitinmanju.medium.com/docker-101-cli-and-basic-commands-to-operate-containers-e6ce73a516d">next chapter</a> and dive deeper into managing containers using the Docker CLI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55ffe0994f95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Notes to save time and be efficient while working from home]]></title>
            <link>https://nitinmanju.medium.com/notes-to-save-time-and-be-efficient-while-working-from-home-e04b25d5f6fc?source=rss-ea1e000d6e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/e04b25d5f6fc</guid>
            <category><![CDATA[save-time]]></category>
            <category><![CDATA[efficient-working]]></category>
            <category><![CDATA[remote-work-tips]]></category>
            <category><![CDATA[work-from-home]]></category>
            <category><![CDATA[avoid-distraction]]></category>
            <dc:creator><![CDATA[Nitin Manju]]></dc:creator>
            <pubDate>Wed, 02 Jun 2021 11:23:57 GMT</pubDate>
            <atom:updated>2021-06-02T15:43:52.606Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPWIaENj581k7qLtIEBStQ.jpeg" /><figcaption>image courtesy <a href="https://picjumbo.com/author/viktorhanacek/">https://picjumbo.com/author/viktorhanacek/</a></figcaption></figure><p>In this pandemic, with many of us working remotely from our homes doing desk jobs, it has become tough to manage time, and getting distracted is easy as there is no one “<em>looking</em>” at your desktop other than you. This can lead to extended work hours.</p><p>Here are a few simple tips that have helped me to reduce distractions and manage my own time while working from home. However, this is applicable to anyone who wants to manage time and be efficient.</p><h4>Have a goal for the day,</h4><p>Before you start your work, having a predetermined goal for the day helps a lot. If you have to finish multiple things, always prioritize the tasks based on the most important to the least important. This will help you in estimating the time you will need to finish your tasks.</p><p>It is important to not keep more than two critical tasks on the list. Having many critical tasks can cause panic and you may end up having an unproductive day.</p><h4>And have a deadline for each goal.</h4><p>Having understood the priority of each task, it is important to also understand the complexity and estimate the required time for each task. With this, you can determine how long your workday is going to be and if there is a need to readjust your goals.</p><h4>Avoid long, unwanted discussions during work hours.</h4><p>Working remotely comes with its own set of problems and proper communication with the team is one of them. It&#39;s not the same when compared to the ease of being at the office with your colleagues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*YILBx2jXeBdFimEwDOxoiA.gif" /></figure><p>However, one of the most famous ‘time waster’ is long meetings which could have simply been an email.</p><p>Try to avoid such discussions as much as you can. This will reduce stress and save time. Try to keep communications short and precise.</p><blockquote><em>Ration your time because it&#39;s yours and take care of it since it’s very limited.</em></blockquote><h4>Keep that phone away!</h4><p>Just keep it away! There is nothing more distracting than the chime you hear when you get a notification from a social media account or a friend just forwarding you a meme. If you can&#39;t keep it away for work reasons, at least try to keep it on DnD mode during your work hours. Most modern mobile devices support it. You could also snooze and later view all notifications in a batch by using apps like <a href="https://getdaywise.com/">Daywise</a>.</p><h4>Buy a tiny music player if you are someone who enjoys music while working.</h4><p>If you like working while listening to music but do not want to play it out loud, you could buy a dedicated music player and have some ambient sounds or a few tracks. Use the music player instead of your mobile phone for music/radio. This will also save you some battery on your mobile phone and keep you away from it.</p><blockquote>Limited choice = minimum decision making = maximum utilization.</blockquote><h4>Start early and end early.</h4><p>This is something that most of us are failing to do, I have personally not been able to do this for a long time now. However, starting early doesn&#39;t mean you sit in front of your desktop. It could be as simple as mentally preparing yourself for the day, setting up your goals for the day, and planning for it. This helps a lot and prepares you mentally for the day ahead.</p><h4>Take a break.</h4><p>Take short and well-deserved breaks! Working for long hours without breaks can have a negative impact on your health and productivity.</p><h4>But avoid social media during work hours (including breaks!)</h4><p>Do not use any kind of social media during your work hours. Clicking on that one YouTube link will cost you an entire hour or maybe more. Why? because of what follows after the video ends and the recommendations that you see. Avoid it entirely and stay focused.</p><h4>Workout during the day.</h4><p>Workout is good for you. It releases stress and refreshes your mind to achieve that goal. You can do this during work hours as well. Take a short break and go for a walk or do a couple of reps of Jumping Jacks. It&#39;s healthy and is much better than watching that YouTube video!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1b98WrRrmUs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1b98WrRrmUs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1b98WrRrmUs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0acb3847d2d34977d4a2db9234d2796a/href">https://medium.com/media/0acb3847d2d34977d4a2db9234d2796a/href</a></iframe><p>Here are a few benefits of <a href="https://www.healthline.com/health/fitness-exercise/benefits-of-aerobic-exercise#benefits">cardio</a>.</p><h4>Eat healthy, hydrate, and get an ample amount of sleep.</h4><p>Last but not the least, keep yourself hydrated, plan a proper diet and bedtime schedule.</p><p>Waking up with a groggy mind is not going to help you achieve your goals and will have a negative effect throughout the day. Get ample amount of sleep.</p><p>That&#39;s all for now. I will add items to this list if I find something else that has helped me. Do leave your comments if this has helped you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e04b25d5f6fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>