Establish Connection between MySQL and Apache in a Containerized Web Application

This blog is the continuation of the previous blog of build a Containerized Web Application on Azure (Click here to read the previous blog) . In this blog, we will establish a connection between mysql-container and apache-container.

Now watch those containers with this command:

watch 'sudo docker ps -a'

If mysql-container stops then restart it using following command:

sudo docker start mysql-container

Open the mysql-container shell using the following command and check the status of the mySQL service.

sudo docker exec -it mysql-container bash
service mysql status

If MySQL service is not running then start it using the following command:

service mysql start

We have installed the network tools in the apache-container. Now install the network tools in the mysql-container.

apt install inetutils-ping net-tools -y

Checking Connection

Check network cards in the mysql-container.

ifconfig

And note down the IPaddress of the mysql-container and exit from this container and move to host machine. In my case, It is 172.17.0.2.

Read More »

Build a Containerized Web Application on Azure

In this blog, I am going to setup MySQL server in one container and apache2 in other container and If you are not familiar with Docker, read my this blog first(Click here to read the blog). Moreover, this all will be done on Azure virtual machine, If you are not familiar with Azure virtual machine, please read my this blog first to create the virtual machine on Azure(Click here to read the blog).

Setting Up Docker

To install Docker, use the following command:

sudo apt install docker.io

To start docker, command is given below:

sudo systemctl start docker

To start docker, when you start the ubuntu use this command:

sudo systemctl enable docker

To view current images, use the following command:

sudo docker images

To pull images, use the following command:

sudo docker pull ubuntu

Creating MySQL Container

We have already downloaded the ubuntu images. Now using this ubuntu image we will create the container and named it mysql-container. Because we are going to install MySQL database in it.

sudo docker run --name mysql-container -it ubuntu

Now you are in mysql-container, execute the following comand to set the environment and install the vim for editing.

apt update
apt install vim -y
exit

If you want to see which container in running on your host machine use this command:

Read More »

Flask Website Deployment using Docker Compose on Azure Cloud

In this blog, I will deploy FLASK app on nginx using Docker Compose. If you don’t have any idea how Docker Compose works, read my previous blog first (Click here to read the previous blog).
Before we move to work, I will give you brief intro the things which I am going to use. I created a virtual machine on Azure Cloud Platform. If you don’t know, how to create virtual machine on Azure, go to my this blog create virtual machine easily with few simple steps (Click here to read the blog).
After creating virtual machine just ssh into your machine using simple command.

ssh halcyoona@40.114.31.5

Installation

To install Docker the in your virtual machine, type the command in terminal and press enter:

sudo apt install docker.io
sudo apt install docker-compose

Create a directory with the name of your app, like I am creating my_flask_app.

mkdir my_flask_app
cd my_flask_app

In this floder create two more directory with the nginx and flask. Nginx is entry point of the app, where we get request and then we redirect those request to flask app.

mkdir flask
mkdir nginx

Flask App Setting

Now move into flask directory and create python virtual environment but first install package that is required to create the virtual environment i.e venv first then create virtual environment using following command:

cd flask
sudo apt install python3-venv
python3 -m venv env

Now activate the environment with the simple command:

soure env/bin/activate

And then install flask and uwsgi.

pip install flask uwsgi

flask package is used to create the applications.
uwsgi is a Web Server Gateway Interface used to communicate to nginx server.

Read More »

Getting Started With Docker Compose

In this blog, I will discuss Docker Compose and basic workflow of Docker Compose. But if you don’t know any thing about Docker technology read my blog about Docker first.

Docker Compose, a tool for defining and running complex applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.Docker Compose is mostly used as a helper when you want to start multiple Docker containers and don’t want to start each one separately using docker run. Docker Compose allows configuring and starting multiple Docker containers. All of that can be done by Docker Compose in the scope of a single host.

Docker Compose Workflow

There are three steps to using Docker Compose:

  • Define each service in a Dockerfile and this will create a container for this service.
  • Define the services and their relation to each other in the docker-compose.yml file. And how they are going to communicate to each other, all the rules are defined in this file.
  • Use docker-compose up to start the system. You have to use only this command to start the whole system.

Fast Update

When you change some file in one service i.e update the code or any other changes, you have to restart the docker-compose to reflect the changes but the important things is that, only those containers are going to build again whcih are updated. Compose re-uses the existing containers. Re-using containers means that you can make changes to your environment very quickly.

If you want to deploy a website using Docker Compose check out my blog on deployment (Click here to go to deployment blog).

Creating VM on Azure Cloud using CLI, Creating a User and Running Task in Background

In this blog, I am going to show the process of installation of Azure CLI tool and then using this tool to create a ubuntu virtual machine and then accessing this virtual machine through ssh and then add one user and then adding their private key and running one job in their environment.

The first thing you need is the tools that are required. The first tool you required is Azure CLI . You can install Azure CLI simple using the following command:

sudo apt install azure-cli

To use the Azure CLI tool you need first to login into your account through terminal. For this purpose use following command:

az login

When you enter this you will be redirected to the browser, there you can enter your login detail. When you entered then you will get this type of message on your terminal.

You have logged in. Now let us find all the subscriptions to which you have access...
The following tenants require Multi-Factor Authentication (MFA). Use 'az login --tenant TENANT_ID' to explicitly login to a tenant.
b76df79f-0110-465c-90f3-07df4642315d
[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "4ea778976d-32bd-7f5f-aaa5-084cb61a0b0f",
    "id": "37623de4-e2df-4d06-8754-bd88314b4bd0",
    "isDefault": true,
    "managedByTenants": [],
    "name": "Azure for Students",
    "state": "Enabled",
    "tenantId": "5ea9899d-30bd-4f6f-aaa5-084cb61a0b0f",
    "user": {
      "name": "halcyoona@gmail.com",
      "type": "user"
    }
  }
]

Now you are logged in and you can use the Azure CLI tool to create resources from CLI.

az group create --name halcyoona-group --location eastus

When you execute above command you get following output:

{
  "id": "/subscriptions/95623de4-e1df-4c06-9954-bd66314b4bd0/resourceGroups/halcyoona-group",
  "location": "eastus",
  "managedBy": null,
  "name": "halcyoona-group",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

In Azure, all resources are allocated in a resource management group. Resource groups provide logical groupings of resources that make them easier to work with as a collection.
You have to set the name of the resource and then location. Now the resource group is set then move to next creating a virtual machine with this resource.

From now We look forward to creating a virtual machine using the Azure CLI. Use following command to create virtual machine.

az vm create --resource-group halcyoona-group --name halcyoonaVM --image UbuntuLTS --generate-ssh-keys --output json --verbose

In this you have to set the name of the virtual machine. Second Image you want in your machine. Generate ssh key to access it without password using your private key and if you do not specify key name, it will create a key in ~/.ssh/id_rsa.pub by default. Output will be in json form.

Read More »