. NET Core Web App deployment to Docker run

Source: Internet
Author: User
Tags dotnet install node docker hub docker run

Source: Portal

Environment Introduction:

Virtual machine: VirtualBox 5.1.6

System: Ubuntu 16.04.1 LTS

After the system is ready, you can use sudo apt-get udpate and sudo apt-get upgrade to update the system, and then open https://www.microsoft.com/net /core#ubuntu This URL to install the. NET core runtime environment in Ubuntu systems. Copy/paste the given command directly.

Installing Docker:

What is Docker? Here is not introduced, directly open the https://www.docker.com/what-docker to see it or Google's own Chinese introduction.

Docker installation is also the use of the official step by step installation steps. If you do not want to see the introduction can be directly using the following I tidy command:

//execute these commands sequentially:sudoApt-getInstallApt-transport-https ca-CertificatessudoApt-key adv--keyserver HKP://p80.pool.sks-keyservers.net:80--recv-keys 58118e89f3a912897c070adbf76221572c52609d//Open/etc/apt/sources.list.d/docker.list This file and create one if it doesn't exist (sudo touch docker.list)//enter the following line in the Docker.list:Deb https://apt.dockerproject.org/repo ubuntu-xenial Main//then execute the command .sudoapt-Get updatesudoApt-get Purge lxc-dockerapt-cache Policy docker-enginesudoapt-Get updatesudoApt-getInstalllinux-image-extra-$ (uname-R) linux-image-extra-Virtualsudoreboot //restart system sudoapt-Get updatesudoApt-getInstalldocker-enginesudoService Docker start

After the above command executes, be sure to look at the results of the response, some will be prompted not to update, ignore. Next we execute the classic Hello-world. commands are as follows:

sudo Docker run Hello-world

Executing this command will first pull the image named Hello-world from the Docker's Mirror repository (https://hub.docker.com/) and run locally. After successful operation, we will see the Hello world output.

Here, Docker provides a place to centrally manage the image, https://hub.docker.com/, where we can find the base image we want, and we can also push our own image into the Docker's mirrored repository. , provided that you register a docker hub account.

Pull. NET Core Image:

After the Docker installation was successful, we went to the Docker hub to find the dotnet core base image (https://hub.docker.com/r/microsoft/dotnet/) that was maintained by Microsoft. Execute the following command to pull the image locally:

Docker Pull Microsoft/dotnet

After waiting for the image to be pulled to the local, we run the following command and see if the dotnet core environment is normal (it is redundant here, how can MS give an image that cannot be used?). ):

Docker run-it Microsoft/dotnet/bin/bash

This is the command line that goes into the container. We then enter dotnet--version to see the dotnet CLI version number in the current mirror: 1.0.0-preview2-003131. Enter exit return to exit the container.

Okay, now there's the dotnet core Docker image.

Create an ASP. NET Core Web app:

At the beginning of the article, I have already installed the dotnet core environment in the Ubuntu virtual machine. Use the following dotnet CLI command to create an ASP. NET Core Web app and try to run:

mkdir web_2cd web_2/-t webdotnet restoredotnet run

We tried to run and saw that the run was successful. Next use dotnet publish to publish the app, which is published by default to the bin/debug/netcoreapp1.0/publish/directory.

Note: If you do not modify the scripts node inside the Project.json, you will use node. js to temporarily comment out the prepublish, or install node. js with NPM (Install node. JS comes with) install G ULP Bower these packages.

Command:npm install-g Gulp Bower

Write Dockerfile:

In the app root, create a file named Dockerfile (command:touch Dockerfile) to edit Dockerfile (command:VI Dockerfile), enter the following:

# declaration uses the base image fromthe Microsoft//app/ directory under Copy bin/debug/netcoreapp1. 0/publish//app//tcp# Specify app entry point entrypoint ["dotnet  ""/app/web_2.dll"]

Finish writing the Dockerfile, then build a mirror.

Command:Docker build-t web_2.

  Don't forget the point behind the web_2. Once the image has been built, let's run it and try it out.

Command:Docker run-it-p 5000:5000 web_2

Here's what-it means: into the temporary interactive mode.

-P 5,000:5,000 refers to the 5000 port of the container mapped to the 5000 port of the Docker host

Web_2 refers to the image we built just now.

See the temporary interactive command line, which shows the success of the run. My Ubuntu IP is 192.168.10.107. We use the browser to access the http://192.168.10.1075000. Bad, nothing shows, check the HTTP status code is 500, this indicates that the application error. A troubleshooting discovery is a version of the Dotnet core Web app referencing a class library. As you know, the Dotnet core 1.0.1 was released two days ago, and I found in Project.json that the app I created through the dotnet CLI was already using the 1.0.1 version of the class library. However, the base image microsoft/dotnet is still dotnet 1.0.0 class library. Well, if you know the problem, you can change the version referenced in Project.json. Change 1.0.1 to 1.0.0. Execute dotnet restore and dotnet publishagain. Then rebuild the Docker image and run it. Wow, it worked!

Summarize:

With the introduction above, we have experienced running. NET core Web apps in Docker. Step-by-step discovery is to install various execution environments through the command line, with dotnet Core operating environment, Docker running environment, and node. JS Runtime Environment. The relationship with the coder is not too large. Sometimes follow the step by step walk, the result found to be out of reach, this time we need to carefully analyze the error description is what, step by step to find the problem, and solve.

But let's think about what it would be like to automate the above steps. Let's take a moment to imagine. Each time the developer compiles the code submission, it automatically builds the app and automatically publishes it through the CI tool, then automatically builds the Docker image and runs it. After the test passes, the mirror is used directly in the production environment. Then the regression test.

. NET Core Web App deployment to Docker run

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.