This blog is a simple step through, which creates an ASP.NET Core Docker image using Visual Studio 2017, deploys it to Docker Hub and then deploys the image to Azure.
Thanks to Malte Lantin for his fantastic posts on MSDN. See the links at the end of this post.
Code: https://github.com/damienbod/AspNetCoreDockerAzureDemo
2017.02.03: Updated to VS2017 RC3 msbuild3
Step 1: Create a Docker project in Visual Studio 2017 using ASP.NET Core
In the example, an ASP.NET Core Visual Studio 2017 project using msbuild is used as the demo application. Then the Docker support is added to the project using Visual Studio 2017.
Right click the project, Add/Docker Project Support
Update the docker files to ASPNET.Core and the correct docker version as required. More information can be found here:
http://www.jeffreyfritz.com/2017/01/docker-compose-api-too-old-for-windows/
https://damienbod.com/2016/12/24/creating-an-asp-net-core-1-1-vs2017-docker-application/
Now the application will be built in a layer on top of the microsoft/aspnetcore image.
Dockerfile:
FROM microsoft/aspnetcore:1.0.3 ARG source WORKDIR /app EXPOSE 80 COPY ${source:-bin/Release/PublishOutput} . ENTRYPOINT ["dotnet", "AngularClient.dll"]
docker-compose.yml
version: '2' services: angularclient: image: angularclient build: context: . dockerfile: Dockerfile
Once the project is built and ready, it can be deployed to docker hub. Do a release build of the projects.
Step 2: Build a docker image and deploy to docker hub
Before you can deploy the docker image to docker hub, you need to have, or create a docker hub account.
Then open up the console and create a docker tag for your application. Replace damienbod with your docker hub user name. The docker image angularclient, created from Visual Studio 2017, will be tagged to damienbod/aspnetcorethingsclient.
docker tag angularclient damienbod/aspnetcorethingsclient
Now login to docker hub in the command line:
docker login
Once logged in, the image can be pushed to docker hub. Again replace damienbod with your docker hub name.
docker push damienbod/aspnetcorethingsclient
Once deployed, you can view this on docker hub.
https://hub.docker.com/u/damienbod/
For more information on docker images and containers:
https://docs.docker.com/engine/getstarted/step_four/
Step 3: Deploy to Azure
Login to https://portal.azure.com/ and click the new button and search for Web App On Linux. We want to deploy a docker container to this, using our docker image.
Select the + New and search for Web App On Linux.
Then select. Do not click the create until the docker container has been configured.
Now configure the docker container. Add the new created image on docker hub to the text field.
Click create and the aplication will be deployed on Azure. Now the application can be used.
And the application runs as requires.
http://thingsclient.azurewebsites.net/home
Notes:
The Visual Studio 2017 docker tooling is still rough and has problems when using newer versions of docker, or the msbuild 1.1 versions etc, but it is still in RC and will improve before the release. Next steps are now to use CI to automatically complete all these steps, add security, and use docker compose for multiple container deployments.
Links
Orchestrating multi service asp.net core application using docker-compose
Debugging Asp.Net core apps running in Docker Containers using VS 2017
https://docs.docker.com/engine/getstarted/step_four/
https://stefanprodan.com/2016/aspnetcore-cd-pipeline-docker-hub/
[…] Creating an ASP.NET Core Docker application and deploying to Azure […]
Great stuff,thank you for sharing the links and snapshots its really useful
thanks
[…] vind ik onder andere de Docker integratie, Red Gate tooling en betere PowerShell Tools support de meest belangrijke […]