Thursday, December 14, 2017

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



Preliminaries
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 https://aka.ms/template-3pn 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 15.4.8.50001 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 http://v4-alpha.getbootstrap.com/getting-started/browsers-devices/, "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!