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.
- [Required] Azure CLI (install guide).
- [Required] .NET Core (CLI 1.0.0-rc4-004800+).
- [Required] Azure Subscription.
- [Required] git.
- [Required] Docker.
NOTE: all command statements with multiple lines ignore the need for a newline escape.
Build and pubish docker image
First, we need a dockerfile. Minimally, we need a docker file that looks like this.
Next, let’s create a docker image of our web app.
$ dotnet publish -c Release
If you would like, you can check that your image was built properly.
$ 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).
Let’s pubish our image to docker hub (though, you can use any container registry).
$ 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
$ az group create -n DemoGroup -l westus
Finally, we need to configure our web app to run of our docker image.
$ az appservice web config container update --docker-custom-image-name twitchax/netcorehello:v1 -n DockerNetCoreHello -g DemoGroup
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.
$ curl http://https://dockernetcorehello.azurewebsites.net/api/hello/Aaron
That’s it! In about 10 minutes, we have dockerized our web app and deployed it to Azure!