GithubHelp home page GithubHelp logo

216giorgiy / vsts-dotnet-build-aspnet-core-docker-image Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/vsts-dotnet-build-aspnet-core-docker-image

0.0 1.0 0.0 565 KB

This sample demonstrates how to build ASP.NET Core application to Docker images in VSTS

C# 63.27% HTML 31.59% JavaScript 1.79% CSS 3.35%

vsts-dotnet-build-aspnet-core-docker-image's Introduction

services platforms author
.Net
msonecode

How to build ASP.NET Core application to Docker images in VSTS

Introduction:

This example demonstrates how to build an ASP.NET Core Application to a Docker image and run the Docker container in VSTS.

Prerequisites:

1. Private Linux Agent

Refer to the Create and configure a Linux build agent section in the following blog post:

https://blogs.msdn.microsoft.com/jcorioland/2016/08/19/build-push-and-run-docker-images-with-visual-studio-team-services/

2. NET Core

Install .NET Core on your Linux Agent: https://www.microsoft.com/net/core#linuxubuntu

3. npm

Install npm on your Linux Agent: (Ubuntu) sudo apt-get install -y npm

4. bower

Install bower on your Linux Agent: sudo npm install -g bower

5. Get VSTS ready for Docker

Refer to the Get the Docker task and Use the Docker extension in VSTS sections in the following blog post:

https://blogs.msdn.microsoft.com/jcorioland/2016/08/19/build-push-and-run-docker-images-with-visual-studio-team-services/

Building and Running the example:

1. Create an ASP.NET Core application

If you’re using Visual Studio: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc

2. Check the version of .NETCore framework on Docker Host

$ ls -l /usr/share/dotnet/shared/Microsoft.NETCore.App

e.g. output: drwxr-xr-x 2 root root 12288 Jan 5 04:57 1.1.0

3. Add Docker Support

If you’re using Visual Studio:

https://marketplace.visualstudio.com/items?itemName=MicrosoftCloudExplorer.VisualStudioToolsforDocker-Preview

4. Edit/Create Dockerfile

FROM microsoft/aspnetcore:1.1.0
WORKDIR /app
COPY netcore/src/netcore/out .
ENTRYPOINT ["dotnet", "netcore.dll"]

This example assumes the project is structured as following and the application is named as “netcore”:

4

5. (Optional) Update the application from Microsoft.NETCore.App 1.0.1 to 1.1.0

Right click on your project, click Manage NuGet Packages, click Updates to start updating.

6. (Optional) Edit project.json if the application is updated to Microsoft.NETCore.App 1.1.0

{
  "dependencies": {
    ……
    "Microsoft.NETCore.App ": "1.1.0", ==> Delete this line
    ……
  },
  "tools": {
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": { ==> Add this block if it doesn't exist
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      }
    }
  }, 

7. Check your code into VSTS

8. Create a Build Definition

9. (Optional) Add a Shell Script step if private feed is used

https://gallery.technet.microsoft.com/How-to-restore-VSTS-feeds-a2b99e9a

10. Add a Command Line step to restore packages

10-1 10-2

11. Add a Command Line step to publish the application

11

12. Add a Docker step to build an image

12-1 12-2 12-3

13. (Optional) Add a Docker step if you want to push the image to your Docker Registry

13

14. Add a Docker step to run the image

14

15. Queue a new build

16. (Optional) Take a look at the container on Docker Host

$ docker ps

CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS       NAMES
6f1654ed1667        qisha/netcore:73    "dotnet netcore.dll"   44 seconds ago      Up 42 seconds       0.0.0.0:5000->80/tcp    backstabbing_ramanujan

$ wget -S -O NUL http://localhost:5000

--2017-01-16 01:47:03--  http://localhost:5000/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:5000... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
...

17. (Optional) Open the port in firewall

If the host is an Azure VM:

17

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.