Publishing an ASP. NET 5 app as a Docker image (Linux edition)

Source: Internet
Author: User
Tags docker hosting docker hub

Publish the ASP. NET 5 app as a Docker image (Linux edition)?

Tips

This article was updated: December 20, 2015.

Annotations

If you need to run a Docker image on the Windows platform, or use it on Visual Studio 2015, see a later blog post (not currently published) that publishes the ASP. NET 5 app as a Docker image (Windows edition)

Create an ASP. NET 5 project?

First, you need a completed ASP. NET 5 app, and if not, you can refer to the ASP. NET 5 app created on Mac OS. If you're using Windows, creating a web App with vs2015 should be simple enough.

Build docker? Write Dockerfile?

If you are using a yo aspnet generated project, then you have dockerfile, otherwise you will need to create a file named Dockerfile in the project directory.

 from Microsoft/aspnet:1.0.0-rc1 COPY. /appworkdir  /appRUN["Dnu""Restore"]EXPOSE  5000/tcpentrypoint  ["Dnx", "-P", "Project.json", "web"]

Here's an explanation of each line.

    • Since the Docker file system is layered, the from indicates what builds the current mirror, followed by the version number;
    • Copy is to copy the local file to Docker, . indicating the current directory;
    • Workdir specify working directory;
    • Run indicates that a program is running, followed by parameters;
    • EXPOSE indicates that a port number of Docker is exposed so that the host communicates with the container;
    • ENTRYPOINT Specifies the entry point, the first is the program, followed by the parameter.
Start building?

If you haven't installed Docker yet, check here to see how to install it. If you and I have a Microsoft Azure subscription, it's easier to create a virtual machine for Ubuntu on Docker directly.

Building projects

Docker build.

View the build-completed image, where the image ID is the identifier for building the completed image

Docker images

Give the image a name.

Docker tag {IMAGE ID} qinnz/helloworld:0.1.0

In fact, each step in the dockerfile creates a mirror, which is hidden by default. You can view this

Docker Images-a
Run Docker?

Well, you already have an image that needs to be run, and of course you can run multiple instances (though you can't bind to the same port).

 the : qinnz/helloworld:0.1.0bayi: [IMAGE ID}

We launched 2 examples in the background ( -d ) to map the 5000 ports of both containers (which can be identified by using the image ID or tag) to the 80 and 812 ports of the host.

Annotations

The current ASP. NET application needs to be used -t to run correctly.

Tips for creating Docker?

The ASP. NET 5 app created on Mac OS is self Dockerfile -brought and can be used directly. (The operating environment used by default is mono)

However, using this directly Dockerfile will make it necessary to restore the full Nuget package every time, and because the code that is copied first causes a different image to be generated each time. Therefore, each time the code is modified, a new image is generated, typically over 1GB in size.

Therefore, this article recommends using the following method to create a mirror of the NuGet package that has already been restored as the base image (in this qinnz/aspnetpackage case), and then based on this image, you can drastically reduce the time of each Docker Build.

The base image qinnz/aspnetpackage is Dockerfile as follows:

 from MIROSOFT/ASPNET:1.0.0-RC1-FINAL-CORECLR COPY. /appworkdir  /apprun["Dnu","restore"]run ["Dnu","Build"] RUN rm-r/app

The principle is to copy the project file, then proceed dnu restore , and then delete the project file so that the desired NuGet package can be downloaded in the system. Publishing the base image to the Docker Hub can then be built with the following Dockerfile to save time.

Little Tricks

After creating the underlying image, if the next mirror build is done on the same machine, you do not need to push the mirror to the mirrored warehouse.

 from qinnz/aspnetpackage  COPY. /appworkdir  /apprun["Dnu","restore"]Run  ["Dnu","Build"]EXPOSE  entrypoint  ["Dnx", "web"]

Little Tricks

Due to the existence of great gfw, there may be some problems with the local Docker Build. If there is a problem, it is recommended that you deploy a Docker build server offshore.

Little Tricks

Two Chinese Docker hosting platforms are recommended, at least for free to build projects and store image. The Spirit Sparrow Cloud and the Daocloud

Other resources?

Docker

Docker Documentation

Ling Que yun

Daocloud

Publishing an ASP. NET 5 app as a Docker image (Linux edition)

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.