Working with container register + Azure functions + Docker + Node js.

We will explain azure’s functions to work with docker and apply it in a example of Node in Git. We will know the functionalities of these tools, this writing will not be based in the Node example, but this will be based in the combination of the tools.

1. Introduction

1.1 Problematic

In the old days, the old school programmers used a common programming practice which consisted of using virtual machines where they installed all the drivers which were necessary to develop and run applications.

1.2 Inovation

My surprise was finding in these new technologies, the possibility of implement virtual machines (VMs) which use all the power of the hardware, without wasting resources in layers of operating systems, and even crazier, using everything from the cloud support .

Moment. Is that possible?. Yes, it is Azure, a computer service that allows the user to access to have infrastructure and platform in a cloud service, giving unlimited possibilities to programmers. This can be given by hardware, being a type of rental of it, avoiding us to spend our time and money on expensive equipment that will be used seldom. This also applies to servers, giving us a complete experience in terms of platform and infrastructure. This is no longer an issue.

But this is not only thanks to Azure. The Docker platform is the real star of this post.

Docker is a proyect of open source code which automates the deployment of applications inside of software containers, providing an additional layer of abstraction and automatization of the developing of applications in multiple operating systems.

As we mentioned earlier, Docker manages to group all those containers with useful drivers for the application that we want to generate. Simplifying the work of installing drivers and even better, avoiding us the annoying change of operating system. Best of all, you can share your images with preinstalled drivers, and use those which someone else has already uploaded.
This combined with the speed that the Azure platform has, achieves just in matter of minutes, that you are already working in your new project. Everything will depend on you knowing what you want to do and let’s do it!

1.3 What are we going to do?

Since these three tools can be combined to achieve different results, we are going to make a container register in Azure, this will allow us to organize and work with our containers in a working group. Added to this we will work with a Dockerfile in the internal configurations to open the image, code it and launch a Node application.

2. To run our demo.

2.1 Requirements to follow this tutorial

As this is a kind of evangelization of this new technology. We are going to use all the resources and possibilities that we have in Azure to assist Docker.
- An Azure and Docker account
- Install Node.js, Git, Azure CLI, Azure Funtiion Core Tools
- Your favorite code editor

2.2 Create an Azure and Docker account

Open Azure´s page and next create our account. Then we go to Azure Portal. Next create a Docker account (here you can download the images that you are most interested in from Docker Hub).

2.3 Install Node.js, Docker, Azure CLI and Azure Funtiion Core Tools

You must install NodeJS from these link, then Azure CLI and install Docker from this link. From Windows, the installation of all these packages is simple. For the Linux installation, you must follow the instructions given in the console and after that the last steps are done, write the following commands in the console.

npm install -g azure-functions-core-tools

2.4 Create an Azure container record

Within the portal, go to “Create a resource / Containers /Container Registry”

Then we fill all the empty fields with information that we will use again. Do not forget to enable the administrator user.

Once we created this, go to the container´s configurations. There will be two important data in the configuration. Within the configuration keys, in the “access keys” we will find 3 important data: The name of the server to link Azure, the user and password to upload or
download the containers we need.

In the repositories section, we will see all the images that we upload
immediately, so our work group can has them at hand.

2.5 Let’s go to the application of the following example.

In our case, we will use Visual Studio Code, because it is quite popular
and we are Windows 10 users. Let´s get started! Iniciate the first commands and create a folder that will be where our whole project will be saved.

mkdir newfunction
cd newfunction

In this folder, we will copy this example project of this post. Then we will clone with git the next repository that contains a Node project and a server to launch.

git clone https://github.com/mccm2310/azureFunction.git

Once you copy the whole project in our new folder, we will find a odification of a preset image. For this enter in the main repository´s folder.

cd azureFunction

Now we execute the commands of the Azure’s function. This runs the runtime with the Azure or Docker’s

func init . --docker

This will Display the following lines in the console, here we will select Node
and consequently javascript.

We will create and modify the new .json files Now we go with the possible templates that we can run. We execute the following command. Here we will unfold the templates, choose “http trigger” and put the name we want

func new

With this, we will have created our new function.

The next step is build our new image with this function. We use the most commonly used docker commands.

docker build -t azurefunction

If there are doubts about the creation of the files, we can always use the images command to serve us.

docker images

Excellent, now to run the functions. in some requested port. Notice that they do not have the port using another resource. A quick way to solve this is, logically, to change the port.

docker run -p 8080:80 azurefunction

Now check console.

we go to our favorite browser, and put the local address with the port that we enabled

localhost:8080

Congratulations! You ran the application successfully using the combining, Azure functions with Docker. Now, what else can we do with this duo?

2.6 Time to migrate to Cloud.

Another functionality that Azure has with Docker, is to upload our progress to the cloud with respect to the image we have created. We will upload it. First of all, we are going to log in with the following commands, also using the data of the reference image in step 2.2. The console will ask for a username and password.

docker login

First of all, we will tagge it to facilitate use in the console

docker tag azurefunction xxxxxxxxx.azurecr.io/prube123

And finally we’re going to upload it to our container registry.

docker push xxxxxxxxx.azurecr.io/prube123

With this we will share with our group what we have added a base image.

2.7 Team! Time to work.

Now it’s time for the team to work with our newly-developed development. Use the docker command to extract the image from your registry. With the docker pull command, we will be able to bring our container

docker pull xxxxxxxxx.azurecr.io/samples/nginx

Now, let’s run the container in the cloud on a local server. With this command we will be able to do it.

docker run -it --rm -p 8080:80 xxxxxxxxx.azurecr.io/samples/nginx

Go to http://localhost:8080to see the container running. To stop and remove the container, press Ctrl+c.

3. Conclusions.

A fundamental question in programming, is the full knowledge of the tool, to get the maximum potential, many times we waste time doing tests if we have enough knowledge about the tool. This is fundamental when it comes to reduce working time, and that is what Azure is about, which is a costly tool, but very rewarding when it comes to working. Docker is also a technology with a lot of future and would bring great changes in how we prescribe the administration of resources. It has many and great functional, here we have mentioned just a few.

On the other hand we would like to have shown more combinations in the functionalities of both services. But we ran out of time and also became longer than we thought. I hope this files will be useful to you and have fun doing your practices, as much as you enjoy it.

Source

1 Wikipedia® (2019, Jun 19). Microsoft Azure. https://en.wikipedia.org/wiki/Microsoft_Azure

2 Wikipedia® (2019, Jul 3). Docker. https://en.wikipedia.org/wiki/Docker_(software)

3 Escolar Fernando. (2019, March 26). Azure Functions con docker. https://www.developerro.com/2019/03/26/azure-functions-docker/

4 Microsoft © (2018). Azure Functions Documentation. https://docs.microsoft.com/en-us/azure/azure-functions/

5 Scott Hanselman (2018). Get started with Azure Functions. https://azure.microsoft.com/en-us/resources/videos/get-started-with-azure-functions/

6 Microsoft © (2018). Docker en Azure. https://azure.microsoft.com/es-es/services/kubernetes-service/docker/

7 Microsoft © (2018). Container Registry. https://azure.microsoft.com/es-es/services/container-registry/

8 Docker © (2019) Docker Docs. https://docs.docker.com/

9 Microsoft Developer (2018, May 14). From Zero to Azure with Python and Visual Studio Code. https://www.youtube.com/watch?v=DPBspKl2epk&t=521s

10 packtpub (2019, Feb 7). Build & Deploy Web App on MS Azure: Create Azure Container Registry. https://www.youtube.com/watch?v=qdfy6xqTYgk

11 Duque, Julian (2018, December 16). Node.js ¡En Vivo! Docker. https://www.youtube.com/watch?v=ws_BtdSnZ04

12 Campos, Mirlet (2018, Jun 26) Azure Functions and Docker. https://medium.com/@mccm2310/azure-functions-and-docker-27-06-2018-fd6a19f5f872

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store