Introduction
Let’s dockerize our web app! We will be performing all operations using the Azure CLI, and all of our work will be built using Visual Studio Code on Bash On Windows, Linux, Mac OS. If you have not already, make sure you have a .NET Core Web App ready to go.
Prerequisites
- [Required] Azure CLI (install guide).
- [Required] .NET Core (CLI 1.0.0-rc4-004800+).
- [Required] Azure Subscription.
- [Required] git.
- [Required] Docker.
Build
NOTE: all command statements with multiple lines ignore the need for a newline escape.
Build and pubish docker image
Dockerfile
First, we need a dockerfile. Minimally, we need a docker file that looks like this.
1 | FROM microsoft/aspnetcore |
Build image
Next, let’s create a docker image of our web app.
1 | $ dotnet publish -c Release |
If you would like, you can check that your image was built properly.
1 | $ docker run -p 80:80 -it twitchax/netcorehello:v1 |
We can verify that our site is working by navigating to http://localhost/api/name/Aaron (or any endpoint in your app).
Publish image
Let’s pubish our image to docker hub (though, you can use any container registry).
1 | $ docker login |
Create and deploy web app
First, we need to do some setup if you have not already done so (some of these steps may have been completed before, but we need an --is-linux
container).
1 | $ az group create -n DemoGroup -l westus |
Finally, we need to configure our web app to run of our docker image.
1 | $ az appservice web config container update --docker-custom-image-name twitchax/netcorehello:v1 -n DockerNetCoreHello -g DemoGroup |
Test
You can use whatever method you prefer to test your new web app interaction with DocumentDB. In my case, I am using curl
with Bash On Windows.
Get from an endpoint.
1 | $ curl http://https://dockernetcorehello.azurewebsites.net/api/hello/Aaron |
Done
That’s it! In about 10 minutes, we have dockerized our web app and deployed it to Azure!