Face Recognition with Azure, ASP.NET & Docker — Part III

Bernardo Ortiz
3 min readFeb 5, 2019

--

Now that we have our site working is time to create a snapshot and store it on a container.

Before doing all that, what is Docker?

This is what opensource has to say:

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

With that behind us, let’s start by creating a Dockerfile.

A dockerfile is a file that contains instructions for deploying the image inside a container.

Prerequisites:

On your “FaceRecognition” folder create a file called “Dockerfile”, no extension is required, and fill it with this:

  • The first line FROM microsoft/dotnet:2.2-aspnetcore-runtime will download the ASP.NET Core image to your image.
  • Second line WORKDIR \app sets our current working directory inside the app folder.
  • Third line COPY ./FaceRecognition.Web/publish copy all the content of our publish folder into the app folder on the image.
  • Last line ENTRYPOINT ["dotnet", "FaceRecognition.Web.dll is the command that tells docker to run our app dll.

But wait, I don’t have a publish folder…

Open a console on the .Web folder and run the command:

dotnet publish -o ./publish

This packs our app and it’s dependencies into a new folder named publish.

Now we are good to go, open a console on the “FaceRecognition” folder and run:

docker build -t facerecognition .

Now Docker builds the image with the name “facerecognition” into the root directory.

Over the same console run:

docker run -p 5000:80 facerecognition

This command tells docker to run the facerecognition image and publish the container’s port to host on port 5000.

Test the website

Now you can go to “localhost:5000” on your browser, in there you can see the app running in a container on your operative system.

Thanks for reading, I hope you enjoyed this tutorial, see you next time!

--

--