Dockerize your Web App

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.



NOTE: all command statements with multiple lines ignore the need for a newline escape.

First, we need a dockerfile. Minimally, we need a docker file that looks like this.

FROM microsoft/aspnetcore
LABEL name="NetCoreHello"
ENTRYPOINT ["dotnet", "NetCoreHello.dll"]
ARG source=bin/Release/netcoreapp1.1/publish
COPY $source .

Build image

Next, let’s create a docker image of our web app.

$ dotnet publish -c Release
$ docker build -t twitchax/netcorehello:v1 .

If you would like, you can check that your image was built properly.

$ docker run -p 80:80 -it twitchax/netcorehello:v1
Hosting environment: Production
Content root path: /app
Now listening on: http://+:80
Application started. Press Ctrl+C to shut down.

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 publish our image to docker hub (though, you can use any container registry).

$ docker login
$ docker push twitchax/netcorehello:v1

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).

$ az group create -n DemoGroup -l westus
$ az appservice plan create -n DemoPlan -g DemoGroup --location westus --is-linux --sku B1
$ az appservice web create -n DockerNetCoreHello -p DemoPlan -g DemoGroup

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://
    "response": "Hello, Awesome Aaron‽"


That’s it! In about 10 minutes, we have dockerized our web app and deployed it to Azure!

Originally published at on May 5, 2017.