services | platforms | author |
---|---|---|
.Net |
msonecode |
This example demonstrates how to build an ASP.NET Core Application to a Docker image and run the Docker container in VSTS.
1. Private Linux Agent
Refer to the Create and configure a Linux build agent section in the following blog post:
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:
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:
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”:
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
11. Add a Command Line step to publish the application
12. Add a Docker step to build an image
13. (Optional) Add a Docker step if you want to push the image to your Docker Registry
14. Add a Docker step to run the image
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: