Azure

Containerized Azure Features Apps

You’re required to have primary information of Azure Features and newbie degree information of Docker.

  • Create a Docker File
  • Create Container Picture
  • Run Picture Inside Container
  • Testing APIs with Postman

Let’s Get Began 

 

I’ll use my current Azure operate app that was created in my final article.

Step 1 – Create a Docker File
 

Let’s open your operate app venture and go to the Instruments tab and choose Command Line after which choose Developer Command Immediate.

 

 

 

 

 

After opening the window like proven above in your native, proper now you’re the outdoors of your supply code recordsdata, so let’s go inside supply code recordsdata. It is because we are going to create a docker file inside the primary folder the place all recordsdata stay like our lessons, csproj file, and many others. Within the command immediate, write the dir command and hit enter. Now you possibly can see all of the recordsdata and folders that your utility accommodates. Right here, you possibly can see a folder named RESTApiWithAzureFunction, so that is our primary folder the place we are going to create our docker file. To go inside this folder, write the cd {Your folder Identify} command and hit enter. As proven beneath, I highlighted the instructions. 

  1. dir                              
  2. cd RESTApiWithAzureFunction      

 

Now we’re in the proper place and right here we are going to use Azure Features Core Instruments to generate the docker file. Run the next command. This command will create a brand new docker file with all of its dependent base pictures.

  1. func init –docker-only  
 

 

 

 

Step 2 – Create a Container Picture

 

Now we have added a Docker file inside our operate app. Lastly, it is time to create a container picture with its dependent environments. Write the next command in an effort to create the picture. If you have already got all of the dependent base pictures in your native, then it would take a really quick time. Nonetheless, if you’re creating it for the primary time, then it would take a bit longer as a result of at first, Docker will pull all the bottom pictures from the Docker hub that the Azure function-core device mentions contained in the docker file. Within the following command, you possibly can see the docker construct instruction and after that -t will specify the tag that specifies within the command with colon azurefuncimage:v1, and on the finish, you possibly can see a easy dot or interval that signifies the present listing.

 

(Picture Identify = azurefuncimage)

  1. docker construct -t azurefuncimage:v1 .  
 

 

 

 

Step 3 – Run Picture Inside Container

 

We already constructed our Azure operate app docker picture. Run the next command to see all pictures that we’ve in Docker.

Now, we are going to run this picture inside a brand new container. I may even add an surroundings variable within the command that can create and run the container as a result of I need to add my SQL database connection string whereas creating a brand new container. Run the next command to get a brand new container up and working.

  1. docker run -e SqlConnectionString “Server=tcp:growth.database.home windows.internet,1433;Preliminary Catalog=studying;Persist Safety Data=False;Consumer ID={Your ID};
  2. Password= {Your Password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;” -p 8080:80 azurefuncimage:v1  
 

 

The docker run command will run the container based mostly on the picture that I specify on the finish of the command. -n  tag specifying the title of the container and -e tag specifying the surroundings variable and -p tag will map the port that we need to expose to the skin of the container in my case, I’m exposing 8080 port for public accessing and the 80 port is the interior port of the container. On the finish of this command, you possibly can see the picture title with a tag that we created within the final step.

 

Run the next command to see all containers that we’ve in Docker.

Now if you wish to cease your working container, then run the next command in an effort to cease the container. On the finish of this command, add the container Id that you may get utilizing the docker ps command.

  1. docker ps cease containerId

Step 4 – Testing API’s with Postman
 

Open Postman and hit the next URL:

 

Submit Request  – Create a brand new process:

 

 

Get Request – Get Process By Id: 

 

https://localhost:8080/api/process/id 

 

 

 

Get Request – Get Duties Listing:

 

https://localhost:8080/api/process

 

 

 

Azure Perform Logs Inside Container:

 

 

 

What Subsequent?

 

Within the subsequent a part of this text, I’ll show find out how to run containers inside Azure. Additionally, I’ll clarify all steps of find out how to implement steady integration and steady deployment for Azure Perform purposes. Keep Tuned! Develop A REST API With Azure Functions Using SQL

Tags
Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Close