Thursday, December 14, 2017

Create and run an ASP.Net Core app in Linux and use Docker to run it on Windows

I first start with my Ubuntu 16.04 Linux system that has Visual Studio Code (VSC), Docker  and .Net Core installed. My Windows system is running Windows 10 Education version 10.0.16299 with Docker for Windows and .Net Core installed.

From the Ubuntu Linux Desktop
From the command prompt on Ubuntu let’s create a new ASP.Net app.
>dotnet new razor -o demoApp

Here is the output:

 The template "ASP.NET Core Web App" was created successfully.  
 This template contains technologies from parties other than Microsoft, see for details.  
 Processing post-creation actions...  
 Running 'dotnet restore' on demoApp/demoApp.csproj...  
 Restoring packages for /home/mark/Code/dotnetcore/demoApp/demoApp.csproj...  
 Restore completed in 4.1 sec for /home/mark/Code/dotnetcore/demoApp/demoApp.csproj.  
 Generating MSBuild file /home/mark/Code/dotnetcore/demoApp/obj/demoApp.csproj.nuget.g.props.  
 Generating MSBuild file /home/mark/Code/dotnetcore/demoApp/obj/demoApp.csproj.nuget.g.targets.  
 Restore completed in 18.85 sec for /home/mark/Code/dotnetcore/demoApp/demoApp.csproj.  
 Restore succeeded.  

Then in Visual Studio Code (VSC) I open the new demoApp folder:

Next, I opened the About.cshtml Razor file in VSC and made the following changes:

After that, I ran the
>dotnet run
command from the command prompt and browsed to http://localhost:5000/About in my web browser and noted the changes:

I then issued a Ctrl+C at the command prompt to stop the app.

Now to create a Docker image. First, I added a Dockerfile to the demoApp:

I will refer you here for the anatomy of a Dockerfile and here for information about the aspnetcore-build image specifically.

Next, from the command prompt I did the following:

>docker build --rm -f Dockerfile -t demoapp:v0.1 .

This resulted in the following output:

 Sending build context to Docker daemon 2.981MB  
 Step 1/14 : FROM microsoft/aspnetcore-build AS builder  
 ---> e421e10eaa5d  
 Step 2/14 : WORKDIR /source  
 ---> Using cache  
 ---> fde5241ee8a9  
 Step 3/14 : COPY *.csproj .  
 ---> 6015c9b573b7  
 Step 4/14 : RUN dotnet restore  
 ---> Running in 2b79cd9bcc6a  
 Restoring packages for /source/demoApp.csproj...  
 Restoring packages for /source/demoApp.csproj...  
 Installing Microsoft.VisualStudio.Web.CodeGeneration.Contracts 2.0.0.  
 Installing Microsoft.VisualStudio.Web.CodeGeneration.Tools 2.0.0.  
 ...installing many .Net Core 2.0 packages...  
 Installing Microsoft.AspNetCore.ResponseCompression 2.0.0.  
 Restore completed in 21.68 sec for /source/demoApp.csproj.  
 Generating MSBuild file /source/obj/demoApp.csproj.nuget.g.props.  
 Generating MSBuild file /source/obj/demoApp.csproj.nuget.g.targets.  
 Restore completed in 21.81 sec for /source/demoApp.csproj.  
 Removing intermediate container 2b79cd9bcc6a  
 ---> 42f7988a24dd  
 Step 5/14 : COPY . .  
 ---> da398320c33c  
 Step 6/14 : RUN dotnet publish --output /app/ --configuration Release  
 ---> Running in 1b09f2cbe7e8  
 Microsoft (R) Build Engine version for .NET Core  
 Copyright (C) Microsoft Corporation. All rights reserved.  
 demoApp -> /source/bin/Release/netcoreapp2.0/demoApp.dll  
 demoApp -> /app/  
 Removing intermediate container 1b09f2cbe7e8  
 ---> 2c855dca70f5  
 Step 7/14 : FROM microsoft/aspnetcore  
 ---> c8edb557c4f6  
 Step 8/14 : LABEL Name=demoApp Version=0.0.1  
 ---> Running in af48e869c1af  
 Removing intermediate container af48e869c1af  
 ---> 0c656950547f  
 Step 9/14 : WORKDIR /app  
 Removing intermediate container 04f38f1e3c62  
 ---> ee6d00cf12e0  
 Step 10/14 : ENV ASPNETCORE_URLS http://*:80  
 ---> Running in 4eaea7dc650a  
 Removing intermediate container 4eaea7dc650a  
 ---> 6cd5424b62b3  
 Step 11/14 : EXPOSE 80  
 ---> Running in 52745eb44fe4  
 Removing intermediate container 52745eb44fe4  
 ---> 9d71c7fc7f35  
 Step 12/14 : COPY --from=builder /app .  
 ---> 8fd885142f6c  
 Step 13/14 : ENTRYPOINT dotnet demoApp.dll  
 ---> Running in f400dcd4dc15  
 Removing intermediate container f400dcd4dc15  
 ---> 6d41a646da3b  
 Step 14/14 : CMD dotnet demoApp.dll  
 ---> Running in 4e2f93567d8f  
 Removing intermediate container 4e2f93567d8f  
 ---> c55c9141abee  
 Successfully built c55c9141abee  
 Successfully tagged demoapp:v0.1  

Then I tagged the image from the command prompt :

>docker tag demoapp:v0.1 m2web/demo:demoapp

I logged into Docker:

>docker login
>Username (m2web): m2web
>Password: myPasswordHere
>Login Succeeded

I pushed the image to my personal docker repository:

>docker push m2web/demo:demoapp

and it successfully pushed to the docker repo.

Let’s test the image locally by running it from the docker repo:

>docker run -d -p 80:80 m2web/demo:demoapp

Next, browse to the About page that is now running on our localhost:

So we have a Docker image of the ASP.Net Core app that we created on Ubuntu Linux. Now to see it running on Windows 10.

From Windows
In Windows with Docker running make sure that you are ready to run Linux containers. To check this select the Docker icon in the system tray.

Right-mouse click the Docker icon and open the menu that you see below. Note that I have the option to Switch to Windows containers. This means that I am now ready to view Linux containers. If the option is to Swith to Linux containers then select that option as we are going to load the image we created on Ubuntu into a container and run it.

Now open Powershell and let’s run the image from the docker repo locally on the Windows system:

As you can see, I already had most of the base images from previous container loads.

Next, browse to the About page, as we did before on the Ubuntu Linux system and see that our image from the Docker Hub repo is now running on our localhost:

Wednesday, December 13, 2017

Removing an Octopus Deploy Project

To remove a project in Octopus Deploy, first navigate to the project page. Then select the Settings button on the left of the page view. Next, select the Delete button in the lower right-hand of the page.

Finally, confirm the deletion.

Monday, December 11, 2017

Bootstrap does not support Amazon Silk

I have an ASP.Net Core app that I often use on various devices as well as my Kindle Fire. The site utilizes Bootstrap for its look and feel to make it responsive to smaller form factors such as mobile devices. When viewing the site in the Amazon Fire's Silk browser l see that the navigation menu is not collapsed and displaying the traditional "hamburger" as a button:

Instead, the full navigation menu is displayed, obscuring the top part of the page. After during some searching, alas the Silk browser is not supported. From, "Generally speaking, Bootstrap supports the latest versions of each major platform’s default browsers. Note that proxy browsers (such as Opera Mini, Opera Mobile’s Turbo mode, UC Browser Mini, Amazon Silk) are not supported."

Thursday, December 07, 2017

.Net Core, IBM Integration Bus, IBM Toolkit, and Docker...Stay tuned!

It has been a while since I have posted and I have moved from doing ASP.Net development to the Enterprise Integration Services team. On the team I have stared to use IBM's Toolkit on IBM's Integration Bus product. Here, I am learning ESQL. I have also stood up a .Net Core 2.0 ASP.Net app and am fiddling with Docker for development and deployment tasks. Therefore, I will have some posts on the above, even if it is just  beginner's level content as I know that there are others just starting these technologies. Stay tuned!

Wednesday, April 12, 2017

Open Source Code: You can borrow bits, but you get to keep and modify the ideas and give back to others.

You may have heard or seen the following quote at your public library, "You can borrow a book, but you get to keep the ideas." I would like to offer a similar thought in that, "You can borrow bits, but you get to keep and modify the ideas and give back to others." In other words, starting with an existing set of code you can learn from its intent as well as reconstruct it to your own. That is what I love about open source code and tools such as github.

Tuesday, January 17, 2017

Deadlines, the Programming Student, and the 3 Factor Assignment Risks

I know that deadlines drive us all. As I have often heard and said, “Deadlines are your friend.” The problem with these scheduled milestones is when you underestimate the task at hand. While I teach a programming class, let's consider a 5-page paper assignment. For some time, there has been a recognized analogy between writing and programming. As a college student at the 300 level you are accustomed to what is required for a paper. Unlike a writing assignment where you already understand the tools that you are using, word processor of some kind, and a use of the written language that you will be using, you are good to wait until the last day to start.

Specifically, within the typical scenario of a last minute effort there are three factors. One, the concepts of the subject of the assignment. This would include a basic understanding of both high and detail level principles about the topic of the paper as well as vocabulary used in the discipline. Next is the tool(s), as I previously stated, that you will use to compose the paper such a laptop, desktop, or tablet device which has some kind of word processing app such as Apache’s Open Office Writer, Microsoft Word, or a cloud based program such as Google Docs. Finally, the written language in which the work will be created. Typically, the student has a good grasp on the tools and language in which to write the paper. The aspect of the topic of the assignment can generally be picked up with a brief time of applied study.

Yet, this is not the case concerning a computer programming class that offers not only a set of novel concepts, but also a new tool as well as a fresh language in which you will express the desired outcomes. If all three aspects are new to the student, novel concepts, tool (Visual Studio), and language (Visual Basic) waiting until the day before or, perish the thought, the day when the assignment is due, this is at best unwise.

As a technologist that has been in the field as long as most of my students have been alive, I know that there are always what one would call “gotchas” when approaching a new endeavor. In short, these are issues that you do not expect or anticipate. In my long experience, for each project or effort, they happen almost each time. Moreover, if what you are working with is a new tool (Visual Studio) and a new language (Visual Basic), these are risks that must be mitigated. And, the part of the mitigation for any risk is to tackle it early. Therefore, do not wait to start your assigned projects on or even near the assignment deadline. The due date for a programming class assignment signifies the date in which you have met all three of the above factors, not just new concepts.

Saturday, January 07, 2017

NKU BIS 305 Students the Norse Tech Bar Says Don't Wait

Per a tweet from the Northern Kentucky University Tech Bar: 
I agree...don't wait!  :-)