<img src="https://secure.leadforensics.com/133892.png" alt="" style="display:none;">

In the previous article in the series we ran through Dynamics 365 pipelines through a PowerApp, but in this blog we will learn how to containerize Azure DevOps API and push on Docker Hub Repository so everybody can utilize the service and can even extend it further to their specific needs. Apart from that I am not going to explain what dockers, images and containers are as the goal is to play with dockers and come out with some shareable results. Don't worry, there is lot of documentation available on dockers and I will also post links along the way for any commands I use here.

Building and Testing Container Locally

First install Docker for windows as it is essential for managing containers locally and also required for dockers extensions in visual studio code (vs) and classical visual studio 2019 as well. These tools will also help you debugging the containers locally. The source code for our devops api is located on GitHub here with configuration of dockerfile and .dockerignore (specific asp.net core 3.1). Let us clone this repository into vs code locally. It is important to have vs code extensions for docker and Nuget. Now open the cloned folder with vs code and override appsetting.json with valid PPAT (pat) and PURL (devops organization URL) and build the project. If build is successful, open vs code terminal. Now if command prompt shows the root folder path, we have to navigate inside the project folder. For example:

azuredevopsappat

Now we are in project folder on terminal, now run docker's build command to make a new image in format (Repository/Image:Tag). The build command will automatically pick the configuration from dockerfile in project.

dockers

Now, our image and container are ready as shown below in vs code docker's extension or you can view in dockers for desktop as well (in dashboard) or visual studio 2019.

vs code extnesion dockers

Now execute the docker's run command to test on port let say 8888 in browser.

dockers run

Everything works well as I run http://localhost:8888/swagger on browser and test the endpoint http://localhost:8888/api/buildhelper/getallprojects which shows the results.

But you may encounter problems during nuget restore packages depending on your network setup (domain/proxy), means container is unable to access internet. You may have to specify http proxy in nuget config or search in docker's forums or stackoverflow for specific error you encounter during building image. Feel free to connect with me if you need assistance.

Furthermore you can use docker .env file, instead of focusing on appsetting.json values. That is up to your needs and demands as the api code and container repository is public to extend to your needs. In next article we will see how to push container to dockers hub repository directly form GitHub repository.

Push to Docker Hub Repository

Now use the docker's login command then push the image to its repository by getting its ID.

No alt text provided for this image

The results in docker's hub repository can be seen below.

No alt text provided for this image

Pulling from Docker's Hub Repository (testing)

Now remove the image locally and then execute run command again then docker should pull it from its repository online. Remember, it is linux/amd64 container and if you are running on windows 10 with docker for desktop you need to switch to Linux container.

No alt text provided for this image

Job done, but remember you can overwrite appsetting.json values using -env option in run command. For example: (note below is one command):

docker run -it -p 8888:80 --env "PPAT=dummypat" --env "PURL=https://dev.azure.com/{yourorganization}" yesadahmed/azuredevopsapipat:version1.0

This can be very handy as startup command when you deploy this image to Azure on WebApp for Container (WAC) or Azure Container Instances (ACI).

Furthermore if you want to run your container as https locally please follow this.

Source Code

Happy Coding :)

 

Abonner på bloggen!

Diskuter dette innlegget

Tips til lesing

right-arrow share search phone phone-filled menu filter envelope envelope-filled close checkmark caret-down arrow-up arrow-right arrow-left arrow-down