<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Docker | Jacob Aloysious</title><link>https://jacobaloysious.in/tag/docker/</link><atom:link href="https://jacobaloysious.in/tag/docker/index.xml" rel="self" type="application/rss+xml"/><description>Docker</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><lastBuildDate>Wed, 30 Dec 2020 00:00:00 +0000</lastBuildDate><image><url>https://jacobaloysious.in/images/icon_hu4591c05f594249c11c1e99a3a8f1f246_3759739_512x512_fill_lanczos_center_2.png</url><title>Docker</title><link>https://jacobaloysious.in/tag/docker/</link></image><item><title>Docker - DotNet 4.8 - Getting Started</title><link>https://jacobaloysious.in/post/tech_docker_getting_started/</link><pubDate>Wed, 30 Dec 2020 00:00:00 +0000</pubDate><guid>https://jacobaloysious.in/post/tech_docker_getting_started/</guid><description>&lt;p>Source Code:
&lt;a href="https://github.com/jacobaloysious/docker-try-net48" target="_blank" rel="noopener">docker-try-net48&lt;/a>&lt;/p>
&lt;p>&lt;strong>Goal:&lt;/strong> Develop a .Net48 application - coding would happen in the host while its run inside the docker - live&lt;/p>
&lt;p>&lt;em>Prerequisite:&lt;/em>
&lt;a href="https://docs.docker.com/docker-for-windows/install/" target="_blank" rel="noopener">Docker Desktop for windows&lt;/a> is up and running and you are using Windows Containers&lt;/p>
&lt;p>There are tons of documentation online, this is just me getting started.&lt;/p>
&lt;h2 id="base-image">Base Image:&lt;/h2>
&lt;p>There are two base images supported officially by Microsoft for .Net windows application.&lt;/p>
&lt;ul>
&lt;li>Windows Server Core&lt;/li>
&lt;li>Windows Nano Server&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="DotNetContainer.jpg" alt="alt Components" title="Base Window Images">&lt;/p>
&lt;p>In this example: we are gona work on a .Net Framework 4.8 - console application. We would be using the
&lt;a href="https://github.com/microsoft/dotnet-framework-docker/blob/master/src/runtime/4.8/windowsservercore-ltsc2019/Dockerfile" target="_blank" rel="noopener">&lt;strong>DotNet Framework 4.8&lt;/strong>&lt;/a> image which internally uses
&lt;a href="https://hub.docker.com/_/microsoft-windows-servercore" target="_blank" rel="noopener">&lt;strong>servercore:ltsc2019-amd64&lt;/strong>&lt;/a> as base image.&lt;/p>
&lt;p>Let first pull the image, into our local image cache. This would take a while as the size is huge - get yourself a coffee.&lt;/p>
&lt;pre>&lt;code>$docker pull mcr.microsoft.com/dotnet/framework/runtime:4.8
&lt;/code>&lt;/pre>
&lt;p>Once pulled (image is available in your local cache) - you are gona see an entry with Tag &lt;strong>4.8&lt;/strong> in image list&lt;/p>
&lt;pre>&lt;code>$docker image ls
&lt;/code>&lt;/pre>
&lt;p>&lt;img src="PullDotNetImage.jpg" alt="alt Components" title="Pull DotNet Image">&lt;/p>
&lt;h2 id="sample-app">Sample App:&lt;/h2>
&lt;p>Here is a sample app to demostrate the usage. Clone the
&lt;a href="https://github.com/jacobaloysious/docker-try-net48" target="_blank" rel="noopener">repository&lt;/a>. Open the solution &lt;em>jacapp.sln&lt;/em> in VS2019 and compile it. Its a simple app which starts two threads and exits after 10 seconds&lt;/p>
&lt;ul>
&lt;li>One thread - print the count and the thread ID - to the &lt;em>console&lt;/em> every second&lt;/li>
&lt;li>Second thread - write the same count and thread ID - into an &lt;em>output text file&lt;/em> every second&lt;/li>
&lt;/ul>
&lt;p>&lt;em>note:&lt;/em> the output file would be on a volume mounted drive with the host&lt;/p>
&lt;p>&lt;img src="reposcreenshot.jpg" alt="alt Components" title="Repo Content">&lt;/p>
&lt;h2 id="dockerfile">Dockerfile:&lt;/h2>
&lt;p>Let&amp;rsquo;s look at the contents of the dockerfile:&lt;/p>
&lt;ol>
&lt;li>Specify &lt;strong>Base image&lt;/strong> we plan to use - in our case we are gona use the image (4.8 Runtime) we have already downloaded (pulled)&lt;/li>
&lt;li>Specify the &lt;strong>Working Directory&lt;/strong> where all the commands would be run. Think of it as running &lt;code>$CD /d c:/myapp&lt;/code>, before the &lt;em>EntryPoint&lt;/em> is exectuted&lt;/li>
&lt;li>Specify the &lt;strong>Command&lt;/strong> to be executed inside the working directory. In our case its the console app, so we run the output exe &lt;em>jacapp.exe&lt;/em>&lt;/li>
&lt;/ol>
&lt;p>&lt;img src="docker-file.jpg" alt="alt Components" title="Dockerfile Content">&lt;/p>
&lt;h2 id="build-image">Build Image:&lt;/h2>
&lt;p>Let&amp;rsquo;s build a docker image. Run the command from the directory which has the &lt;code>Dockerfile&lt;/code>&lt;/p>
&lt;pre>&lt;code>$docker build -t testapp .
&lt;/code>&lt;/pre>
&lt;p>&lt;img src="docker-build-image.jpg" alt="alt Components" title="Dockerfile Content">&lt;/p>
&lt;p>&lt;img src="test-app-image.jpg" alt="alt Components" title="Test App Image">&lt;/p>
&lt;h2 id="run-image">Run Image:&lt;/h2>
&lt;p>Items to note:&lt;/p>
&lt;ul>
&lt;li>&amp;ndash;name: name of the container image instance&lt;/li>
&lt;li>-v: volume mount; here we mount the output &amp;ldquo;bin&amp;rdquo; directory with a specific directory inside the container &amp;ldquo;c:\myapp&amp;quot; .&lt;/li>
&lt;li>-rm: remove the container instance once the program exits&lt;/li>
&lt;/ul>
&lt;pre>&lt;code>$docker run --name jacinstance1 --rm -v D:\dev\dkr\docker-try-net48\jacapp\bin\Debug:C:\myapp\ testapp
&lt;/code>&lt;/pre>
&lt;h4 id="instance-of-the-containter-running">Instance of the containter running:&lt;/h4>
&lt;p>&lt;img src="jac-instance.jpg" alt="alt Components" title="Run Console Output">&lt;/p>
&lt;h4 id="console-output">Console output:&lt;/h4>
&lt;p>&lt;img src="run-console-output.jpg" alt="alt Components" title="Run Console Output">&lt;/p>
&lt;h4 id="contents-of-the-file-writted-on-the-mounted-drive">Contents of the file writted on the mounted drive:&lt;/h4>
&lt;p>&lt;img src="run-output-file-content.jpg" alt="alt Components" title="Run Console Output">&lt;/p>
&lt;p>Well thats it! We have our application running inside a container - Now we could edit your project (try updating the console output text), compile and directly &lt;code>docker run&lt;/code> the image i.e. NO docker image re-build required!!&lt;/p></description></item></channel></rss>