Running the Linux container ASP. NET 5 cross-platform application in Azure

Source: Internet
Author: User
Tags asp net docker hub docker run docker toolbox

In a previous blog, it was not difficult to understand how to publish an ASP. NET application directly to Windows Server TP3 in Azure public cloud via the virtual Studio 2015 Docker Extension tool. , after all, the Windows Server kernel is required for Windows to run. NET applications, but the foreshadowing here is ASP. NET 5 (VNEXT) Open source project with DNX (. Execution Environment running environment) Will Bootstrap. NET application, SDK tools, and the CLR cross-platform capability, so we can also publish the Web application or console program of ASP. DNX to a host or Docker container with a Linux or Mac OS containing the environment, and with the help of container technology, Our application hosting process is really not only cross-platform and can cross the cloud environment, this is not thinking about happy things? Hehe: The Docker container image of the ASP. NET Preview version is currently available on Dockerhub.


The next step is to show you how to publish your own ASP. NET 5 Preview application to a Linux virtual machine container running on the azure public cloud, using a client that is my test machine Windows 10 Client environment, the first way to ensure that the following components are installed on the test machine:

    • Git for Windows or GitHub desktop

    • Azure CLI or Azure Powershell

    • Docker Toolbox 1.8.x

In the first way, we need to get our tests using the ASP. NET project, connect and build our Docker virtual machines published on Azure side and build and run our project container.

The second way please refer to my previous blog on the test machine has installed Virtual Studio 2015 development IDE and virtual Studio The 2015 Docker extension tool can build Docker's Linux virtual machines directly on Azure and publish them to Azure, which eliminates the need for these components to be built and deployed independently.

Please note: The current expansion of Docker is not supported in the domestic version of Azure, so this article describes the features that are available in the international version of Azure to implement and test subscriptions that require an international azure cloud environment, and the ASP. NET 5 Docker image is currently in the preview phase, and even in my testing process, I have encountered and solved some problems, so if you follow this technology and project, keep your eye on the changes in the Docker hub and the documentation for the project updates in the GIT library.


The first step is to pre-prepare the Linux virtual machine on Azure for Docker creation

To package our application to the ASPNET image and run the container, we first need to build the hosted Docker Linux virtual machine environment on Azure, because the process is simpler if you don't know what to do, you can refer to this document and create it directly from the Azure portal marketplace. If you have consulted my previous blog, you can also use the virtual Studio Docker extension to select the Linux environment VM image in the Create step, see:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/F1/wKiom1Xv_PvRqzXkAAHxV8eB3XQ768.jpg "/>

The test environment in this article uses the Ubuntu Server 15.04 version.

Next, regardless of the way you deploy the ASP. NET 5 application, we are on azure we have built a Linux Docker virtual machine environment for the deployment of our applications.

Next, we'll cover two ways:

Mode 1, Creating an image that contains an ASP. NET application for container creation; one of the great charms of Docker is the expansion of a layer of lightweight extended image layers through the Aufs file system, which allows us to build our standardized application Runtime environment package based on an original image, one layer at a time, and the base image we need here is Micros Oft/aspnet Open Source project image, so we just deploy the image in an Azure Docker virtual machine environment before we add the application package, the new image created is just a code-based checkin, which is lightweight and very fast to deploy. This is one of the reasons why Docker is so popular in open source environments.

Deploying the base image and adding our code process as long as it is built with the declarative dockerfile provided by Docker, the detailed usage syntax for Dockerfile can refer to the official Docker documentation, which is not discussed here.

This method of testing we directly refer to the Web Application sample code in Aspnet/home, so we first cloned the project to a local git library,

git clone [email protected]:aspnet/home.git aspnet-home

Into the project environment, you can see the files in the project as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/ED/wKioL1Xv_yizgbOHAAGY-LlZtdU082.jpg "/>

We open and edit the dockerfile in the directory and modify it to the following:

From Microsoft/aspnet

COPY project.json/app/

Workdir/app

RUN ["Dnu", "restore"]

COPY. /app

EXPOSE 5004

entrypoint ["Dnx", "Kestrel"]

(I used a cool free IDE when I tested it, but I'm interested in the virtual Studio Code that supports Dockerfile syntax IntelliSense.) See

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/F1/wKiom1Xv_PzDnekoAADANtmGbdo445.jpg "/>

What has dockerfile done here? Constructs an image process that adds test code to illustrate, first from help us find and download aspnet:latest latest base image from Dockerhub to the Docker virtual machine environment deployed on Azure side.

Next, copy helps us copy the JSON file defined by the local project to the Mount base image/app directory for DNU deployment, and then Workdir sets the current working path to/app,copy. /app help us to upload the current cloned Git sample code to the/app directory of the base image, and finally set the Web outbound service listening port to 5004, We can see the ASPNET service port started by Kestrel in the definition shown in Project.json, and the entry at the start of the container is "Dnx Kestrel" to start the kestrel environment and apply the definition in Project.json at startup.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/ED/wKioL1Xv_yrQo-rHAAMRLGlUA38988.jpg "/>

Okay, now we have the application base image environment that can be built with code, including Dockerfile,project.json and our application projects. Here we start connecting Azure Docker virtual machines and restful Web Access Docker Deamon with TLS encryption to get Dockerfile build an entire Docker image:

Docker--tlsverify-h Tcp://{your Azure Docker VM DNS name}:2376 build-t MyApp.

Here are my settings when I test:

Docker--tlsverify-h tcp://vnextserver.westus.cloudapp.azure.com:2376 build-t MyApp.

Once completed, you can view the Aspnet:latest base image to the image and the MyApp image that extends the test app has been created.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/F1/wKiom1Xv_P-yABgbAAMqC-Wq3rw376.jpg "/>

And then we just have to create the container to run the process with this image,

Docker--tlsverify-h tcp://{Your Azure Docker VM DNS name}:2376 run-t-d-p 80:5004 MyApp

Actual test settings:

Docker--tlsverify-h tcp://vnextserver.westus.cloudapp.azure.com:2376 run-t-d-p 80:5004 MyApp

For information on the parameters and methods used by Docker run, please refer to the official documentation, here is a brief description,-T for the container hook up a pseudo-tty, it is said that the parameter future ASPNET container creation will no longer be required.

The-D representative will start the container process in the background, and p specifies the port that the container port exposes to the Azure Docker virtual machine, which is set to a 80 mapping, note here that the container's network environment in the cloud feels like stealing dream space or wormhole crossing, Burn not burn brain may look at our state and IQ, open a joke, see, network hierarchy mapped out there are several levels, the above command completed the container service port is mapped to the virtual machine's external port 80, However, if you are accessing an extranet service on Azure, you also need to map the extranet port to the virtual machine via load balancing or endpoint endpoint, as well as the network access control policies that may be controlled through the azure NSG, which can be described through the network section of Azure. here does not expand the introduction, later do more blog slowly introduced.   

650) this.width=650; "width=" 740 "height=" 369 "title=" 1.png "style=" width:631px;height:310px; "src="/HTTP/ S3.51cto.com/wyfs02/m01/72/ee/wkiol1xwarhg-z_0aagetcoovic927.jpg "alt=" Wkiol1xwarhg-z_0aagetcoovic927.jpg "/>


Check to see if the container we created is already running.

Docker--tlsverify-h tcp://{Your Azure Docker VM DNS name}:2376 PS

Actual test settings:

Docker--tlsverify-h tcp://vnextserver.westus.cloudapp.azure.com:2376 PS

Access to 80 ports on the azure virtual machine extranet, and now our ASPNET test application is already running in the Azure Public cloud Linux Virtual machine container environment, what if the task across the cloud spanning the platform is complete:)

650) this.width=650; "Width=" 1018 "height=" 571 "title=" 2.png "style=" width:824px;height:463px; "src="/HTTP/ S3.51cto.com/wyfs02/m00/72/ee/wkiol1xwayoq_t2aaaig_e9lwxe991.jpg "alt=" Wkiol1xwayoq_t2aaaig_e9lwxe991.jpg "/>

Next, let's introduce the second approach, which is the ability to publish ASP. NET to Azure Docker virtual machine directly through virtual studio, thanks to integrated support for the Docker CLI, if you are not a deep user of Docker, You can focus more on your code itself, let IDE tools help you with publishing and deployment work, how about it? Cool it!

Here are just a few things to tell you about the release method, first of all to make sure that we've prepared the Docker virtual machine on Azure as required in the pre-prep phase (we created the best with our IDE, of course), and then we still select the ASP NET Web project I used in my previous blog, We do a little bit of modification to the deployment, and my test found a small bug in the Project.json file generated by the current version of the tool, so we need to make a simple modification, which should be addressed in the Dockervirtual Studio 2015 extension tool released later.

To open Project.json in the virtual Studio project, modify the section:

650) this.width=650; "width=" 785 "height=" 411 "title=" 3.png "style=" WIDTH:580PX;HEIGHT:334PX; "src="/HTTP/ S3.51cto.com/wyfs02/m02/72/ee/wkiol1xwab7xaspdaajtr_ese54883.jpg "alt=" Wkiol1xwab7xaspdaajtr_ese54883.jpg "/>

Note that when you publish your project to azure through the extension tool, the container port is matched to the configuration port;

650) this.width=650; "title=" 4.png "src=" Http://s3.51cto.com/wyfs02/M00/72/EE/wKioL1XwAfrC24t5AAEi973eGoE315.jpg " alt= "Wkiol1xwafrc24t5aaei973egoe315.jpg"/>


To make sure that our published projects are updated, we simply modify a page about.cshtml the C # tag code that expands the HTML via razor, showing the container in which our current app runs:

650) this.width=650; "title=" 5.png "src=" Http://s3.51cto.com/wyfs02/M00/72/F1/wKiom1Xv__bglajAAADO1k9WSEE004.jpg " alt= "Wkiom1xv__bglajaaado1k9wsee004.jpg"/>

Then publish our app, post it to the Azure Docker virtual machine extranet for verification, open the About page to see the currently running container name:

650) this.width=650; "title=" 6.png "src=" Http://s3.51cto.com/wyfs02/M01/72/F1/wKiom1XwACyCWo57AAEcnXyyZv0495.jpg " alt= "Wkiom1xwacycwo57aaecnxyyzv0495.jpg"/>

Let's check the current running container, Bingo, that's it, we've released an update that's already in effect.

650) this.width=650; "title=" 7.png "src=" Http://s3.51cto.com/wyfs02/M02/72/EE/wKioL1XwAoXh-XDAAACZM-IF_xc626.jpg " alt= "Wkiol1xwaoxh-xdaaaczm-if_xc626.jpg"/>

In the end, this blog shows you two ways to deploy an ASP. NET 5 application running in a Linux container running across platforms in an azure public cloud, and personally feeling through virtual Studio 2015 is indeed a development + deployment tool, But if you are a deep user of Docker, there is no way to use the first. It is important to note that the ASP. NET's underlying images and projects are constantly being updated in the as well as the Virtualstudio Docker extension tools, so your testing or validation process may be slightly inconsistent, suggesting that you are interested in continuing to follow the progress of these projects.



Run the Linux container ASP. NET 5 cross-platform application in Azure

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.