Introduction
Managing an applicatio’s dependencies and technology stack across cloud and hosted environments is always a challenge. While developing the application, multiple environment-dependent bugs get introduced in the software lifecycle. Containerization can be one of the effective ways to cater to this issue. It is simply a process of packing dependencies and libraries along with the application.
Docker
Docker is a Linux-based, open-source containerized platform used for building, running, and packaging applications using containers. Unlike Virtual Machines (VM), Docker containers are lightweight, requires less memory, and provide OS-level Virtualization. Moreover, these containers are faster and treat easy to manage application components such as microservices.
In this article, we will explore deploying containerized apps on hosted servers and Azure App Services. We will also briefly introduce and work with different container registries like Docker Hub, Azure Container Registry (ACR) to host container images. We will also cover the CI/CD (continuous integration and continuous deployment) process.
CI/CD of the containerized app for hosted servers
We have source code hosted on Azure Repos, a ubuntu 16.04 Linux Server, and Azure DevOps pipelines for CI/CD. For deploying apps on the hosted server, we need to install an Azure pipeline agent on the server.
DevOps Pipelines
Azure DevOps uses build pipelines for continuous integration and, release pipelines are used for continuous deployments.
Build Pipelines
For the build pipeline, go to the pipelines, specify the repository and branch of source code, select build agent to create the pipeline, and add appropriate tasks. We will build and push docker images to a container registry, i.e., Docker Hub or ACR, copy release yml files, and publish artifacts for release pipelines in the building process.
Source Code & Agent
The user must specify the repository and branch where the “Source code” is available. Azure allows multiple platforms for source control, such as Azure Repos, GitHub, Bitbucket, or any other version control platform. In the build pipeline, deployment agents can be changed or edited in “Get Sources” and “Build Pipelines.”
Build Services
It is a Docker Compose task, which will build Docker image services provided in the “docker-compose.yml” while binding with the configuration of “Dockerfile
The user must provide the appropriate configuration according to needs. Here are the basic configurations for this build services task:
Push Services
This Docker Compose task will push the images built in the previous step to the provided container registry, here we are using “Docker Hub”
The user must create a “Service Connection” to provide the appropriate access to the container registry. This will allow the, pipelines to push the images.
Creating Service Connection
To create “Service Connection” go to “project settings, Service Connections, and add “New service connection”..” Then select “Docker Registry” and add the username and password as shown below:
Copy Release File
We will copy “docker-compose.yaml” for release automation via this task.
Copy Release File
The “Publish Artifact” task involves publishing the build artifacts to the release pipeline to deploy the docker containers.
Release Pipelines
Azure DevOps allows continuous deployment using release pipelines. Just like build pipelines, we must specify the deployment agent in release pipelines too. As we will deploy the application on a hosted server, we will use hosted agents installed as a pre-requisite.
We will connect the release pipeline with its appropriate build pipeline using the Publish artifacts, and stages will be used to pull docker images and spin up the appropriate containers at the hosted destination.
Here are the deployment steps of release pipelines, as shown below:
Copy Release File
In this step, we will copy the “docker-compose.yml” from build artifacts to the appropriate path., tThis file will be used to pull and spin up containers based on the configuration.
Deployment
This bash script task will allow Docker to login into the container registry, stop and remove previously deployed containers, pull the docker images from the container registry and spin up the containers based on the “docker-compose.yml” file.
Verify Deployment
This is a simple task just for test the deployment;, one can see the running containers just by using the ps command as
Post-Deployment
In this section, we will briefly overview Docker Hub images, DevOps pipeline logs, and the hosted application in this section.
Docker Images
Docker images will be created and pushed to the “Docker Hub” [3] repository in the build pipelines. On every successful build, the Docker images will be pushed to the registry.
Pipeline Logs
The user can see the pipeline logs by going to the build or release pipelines accordingly. Moreover, to test deployment verification, a separate task has been added. By clicking the logs, verification of deployment can be confirmed.
Hosted Application
In this scenario, we have a “php” based website, which we will deploy as a containerized app on the hosted server. After successful completion of build and release pipelines, it will be deployed successfully.
CI/CD of the containerized app for Azure Web Services
We have source code hosted on Azure Repos, ACR (Azure Container Registry) for hosting docker images, and Azure DevOps pipelines for CI/CD.
DevOps Pipelines
In this section, we will discuss the build and release pipelines in detail.
Build Pipelines
For the build pipeline, go to the pipelines, specify the repository and branch of source code, select build agent to create the pipeline, and add appropriate tasks. We will build and push docker images to a container registry, i.e., Docker Hub or ACR, copy release yml files, and publish artifacts for release pipelines in the building process.
Source Code & Agent
The user must specify the repository and branch where the “Source code” is available. Azure allows multiple platforms regarding source control, including Azure Repos, GitHub, Bitbucket, or any other version control platform. In the build pipeline, it can be changed or edited in “Get Sources” and “Build Pipelines.”
Build Services
This Docker Compose task will build Docker image services provided in “docker-compose.yml” while binding with the configuration of “Dockerfile”.
We must add an ACR connection, provide a path to the “docker-compose” file, and basic configuration as shown below.
Push Services
This Docker Compose task will push the build images to the ACR (Azure Container Registry). The ACR Service Connection would be required in this step.
Release Pipelines
For continuous deployment, we will use the release pipelines. Just like for the build pipelines, we must specify deployment agents in release pipelines too. We will use Azure-hosted agents as we are going to deploy Azure app services. No dedicated server is required for this process.
We will connect the release pipeline with ACR artifacts giving access to the appropriate container registry, and stages will use the “Azure App Service” task to pull the container images and deploy the application on Azure.
We will use the single “Azure App Service” deploy task in the release management.
Azure App Service Deploy
In this task, we will all specify the Azure App Service name and type to deploy the application on. Multiple additional configurations can be provided given on the requirement need.
Post-Deployment
Docker Images
Docker images will be created and pushed to the ACR (Azure Container Registry) [4] in the build pipelines. On every successful build, the docker images will be pushed to the repository.
Pipeline Logs
The user can see the pipeline logs by going to build or release pipelines accordingly. By going to the App Service task logs, the user can also verify the deployment of the application.
Hosted Application
We have “php” based website, which we will deploy as a containerized app on Linux-based Azure App Service. After successful completion of the build and release pipelines, the application will be hosted.
Enable Continuous Integration (CI)
To enable continuous integration (CI), we must enable the build pipeline triggers. Hence, as soon as the code gets committed, it starts the build pipeline, builds the solution, and publishes artifacts for the release pipeline. We can find that option in “Triggers” in build Pipelines.
Enabling Continuous Deployment (CD)
Like building pipeline triggers, we can enable the release pipeline triggers to enable continuous deployment, allowing the pipeline to deploy the application as soon as the building pipeline successfully triggers.
Explore Azure DevOps: The Ultimate Tool for Software Development
Conclusion
Docker provides a lightweight and microservice model to cater to the overhead of traditional VMs and application dependency issues. In this article, we covered up the brief introduction of Docker and deployed a simple php application for hosted servers as well as Azure App Service. Docker nearly supports every application for more check references. [1]
Moreover, we also overviewed Docker Hub and ACR images, including pipeline logs, and enabled continuous integration and deployment (CI/CD).