Monday, February 3, 2020

Install Docker Ubuntu - How to install Docker in Ubuntu 16.0.4? setup Docker on Ubuntu

Please find the steps needed for installing Docker in Ubuntu 16.0.4 instance.

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-cache policy docker-ce
sudo apt-get install -y docker-ce
sudo systemctl status docker

now press q to come out this.
ps -ef | grep docker

docker --version

sudo docker run hello-world

the above command should display the below message..

you should see below message 
Hello from Docker!
This message shows that your installation appears to be working correctly.

Also, create an account(keep all lowercase in your username)  in the below website for storing docker images in public docker registry..

Saturday, January 18, 2020

How to create Ubuntu 16.0.4 Virtual Machine (VM) in Azure? Create Ubuntu Virtual Machine in Azure and Connect using SSH keys from locally into Azure Virtual Machine

How to Create a Virtual Machine in Azure Cloud?

Creating Virtual Machine in Azure is easy and straight forward. Let us see how to do that in Azure Portal.

Steps to create a Virtual Machine in Azure 

1. Login to Azure portal, go to https://portal.azure.com
2. Click on Virtal Machines.


3. Now enter the details as below or give values per what your subscription(Free Subscription) and requirements:

You can choose Ubuntu 16.0.4 or 18.0.4 from the drop down from Image drop down. Create new resource group as any name.

4. Also enter username as azure (make sure your key has this name and copy content of ssh keys



5. Once done, click on Review + create

6. Download SSH keys by clicking on Download private key and create resource. You should download keys locally.
7. Once created, Click on virtual machines. It may take more than a couple of mins to create the VM.
8. you should see a message like this, download is complete.
9. Click on Home--> Click on Virtual machine


9. Now select that instance, click on connect



10. Now enter the value as it shows below in your local terminal. You can use Git bash in Windows or iTerm in Apple laptop.

go into downloads directory:

cd downloads
chmod 400 myAzureVM_key.pem
11. ssh -i myAzureVM_key.pem AzureUser@your_azure_ip_address


12. Now it should show you that you are connected to Azure.


Wednesday, November 27, 2019

How to upload Docker images to Azure Container Registry - Hosting Docker images in Azure Container Registry

Azure Container Registry is a managed, private docker registry service. You can create and maintain Azure container registries to store and manage your private Docker container images.

It is alternative to Docker Hub. Azure Container Registry allows you to build, store, and manage container images and artifacts in a private registry for all types of container deployments.

Let us see how to upload a docker images from your VM into ACR.

Pre-requistes:
Make sure you have docker installed on your VM.
 
Step 1 - Create Azure Container Registry (ACR)

Go to https://portal.azure.com/
Create a Resource, Give container registry as a name

Click on Create

  
Enter values as mentioned below:
Give registry name, resource group and choose Enable admin user and SKU as Basic 



 Click on Review and then create, now your container registry is been created.

Step 2 - Download sample Python App

Go to your machine where you have docker images stored. perform below command to download sample pythonapp which is already dockerized.
 
git clone https://bitbucket.org/ananthkannan/mydockerrepo/src/master/pythonApp/ 

cd  pythonApp

docker build . -t mypythonapp

type below command:
sudo docker images

this should show docker images you have created locally.

Now go to ACR, click on docker registry you created. Click on access keys under Settings.


Copy value under login server 

Step 3 - Upload your docker images to ACR
Login to Azure Container Registry through command line.
sudo docker login mydockerazureregistry.azurecr.io
Username: mydockerazureregistry

Enter password by copying value below password

Now tag the docker image per as below:
sudo docker tag mypythonapp mydockerazureregistry.azurecr.io/mypythonapp

sudo docker push mydockerazureregistry.azurecr.io/mypythonapp

That's it..Docker image is pushed into ACR. You can see it under Services--> repositories


How to connect to an EC2 instance from local machine after creating EC2 in AWS?

Find the steps to connect to EC2 instance (running in AWS) from your local machine .

Pre-requisites:

1. Keys(for e.g., yourkey.pem) already downloaded in your local machine, preferably in Downloads folder.
2. EC2 is up and running
3. For windows laptop, you need to install Git by downloading from this URL - https://git-scm.com/downloads
4. For apple desktop or laptops, download https://www.iterm2.com/downloads.html

Steps to connect to EC2 instance:

1. Go to AWS console.
2. Click on EC2, click on running instances link





3. Select the checkbox of EC2 you would like to connect to.
4. Click on Action. Copy the url from SSH which looks like below:
For e.g.
ssh -i "mykey.pem" ubuntu@dns_name.compute.amazonaws.com
 

5. Go to your local machine, Open Git bash, navigate to downloads directory like below:
For windows laptop --> cd downloads

steps For iMac only --> cd downloads
chmod 400 yourkey.pem

6. Paste the url from example highlighted above in step # 4.
ssh -i "mykey.pem" ubuntu@dns_name.compute.amazonaws.com
7. say yes when it is asking to connect.
8. now you should be in AWS cloud, screen should tell you something like this:

Last login: Sun Feb 18 19:01:21 2018 from 64.183.186.78
ubuntu@ip-172-31-26-96:~$
 
 

Monday, October 7, 2019

How to configure webhooks in GitHub and trigger jobs in Jenkins - webhook example GitHub - How to Integrate GitHub with Jenkins?

Webhooks allows developers to triggers jobs in CI server (such as Jenkins) for every code changes in SCM. In this article, we will learn how to trigger Jenkins jobs instantly for every code change.


Pre-requisites:

Make sure you install GitHub integration plug-in in Jenkins

1. Go to Jenkins, Create a job. If you already have a existing job, click on configure. Go to build triggers section and choose the below option - GitHub hook trigger for GitScm pooling.


2. Now go to GitHub, choose your repository. Click on settings, Webhooks.

3. Click on Add web hook.

4. You need to enter Jenkins URL & add /github-webhook/ in the end
http://jenkins_public_dns_name:8080/github-webhook/

5. Now enter payload URL as Jenkins URL, select just push event, click on active. Click on Add webhook
6. After you created, click on webhooks.

7. Click on recent deliveries and you should get response 200 as below:

8. Now go and make some code changes in your repo in GitHub.

9. If you look in Jenkins, you will see job is getting triggered immediately.


You can watch these steps on my YouTube channel as well, please see below:

Docker Interview Questions - Popular Docker Interview Questions


Docker Interview Questions - Popular Docker Interview Questions

1. What is the difference between Docker image and Docker container?

Docker container is simply an instance of Docker image.
A Docker image is an immutable file, which is a snapshot of container. We create an image with build command. Docker image contains all your application code along with all the dependencies packaged into this snapshot.

When we use run command, an Image will produce a container.

In programming language, an Image is a Class and a Container is an instance of the class.

2.  Can we run multiple apps on one server with Docker?
Yes, theoretically we can run multiples apps on one Docker server. But in practice, it is better to run different components on separate containers.
With this we get cleaner environment and it can be used for multiple uses.

3. How does docker client communicates with Docker daemon?

Docker client or command line interface, communicated with Docker daemon through APIs. 

    4.     How to enable IPV6 in Docker
Edit /etc/docker/daemon.json and set the ipv6 key to true.
{
  "ipv6": true
}
Save the file.
Reload the Docker configuration file by executing the below command:
systemctl reload docker


   5. How to copy files inside Dockerfile?
     Use COPY command
     For e.g.,
COPY app.py /usr/src/app/

6. How do you see running container in Docker?
docker ps command

7. How do you see all the containers?
docker ps -a command will show all the containers..

8. How to create directory inside Dockerfile?
mkdir -p /var/www/app
or  
WORKDIR /var/www/app 

      9. What are the benefits of using Docker?
      Docker is a very powerful tool. Some of the main benefits of using Docker are as follows:
   
       I. Utilize Developer Skills : With Docker we maximize the use of Developer skills. With Docker  there is less need of build or
release engineers. Same Developer can create software and wrap it in one single file.
       II. Standard Application Image : Docker based system allows us to bundle the application software and Operating system files in a
single Application Image that can be deployed independently.

       III. Uniform deployment : With Docker we can create one package of our software and deploy it on different platforms seamlessl y
 
      10. What happens when you stop the container? Will you loose the data?
You won’t lose any data when Docker container exits. Any data that your application writes to the container gets preserved on the disk until you explicitly delete the container. The file system for the container persists even after the container halts.