Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

Saturday, August 13, 2022

How to install Java on EC2



*****************************************
How to install Java on EC2
*****************************************





To be continued, In this post, we will see how to install java in EC2


Step 1: Check if java is already installed java version javac -version
Step 2: Update existing packages sudo yum update

Step 3: Make a new directory and switch to directory java
“mkdir java”
“cd java”

Step 3. Now install java on the EC2 server

1. Go to Root Directory
“sudo su”

2. Check if java exist
“java -version”

3. Install java
“yum install java-1.8.0”
It will start installing  java of version 1.8, you can also use the latest tag to install the latest version of java
“yum install java-latest”

4. Check java, if java is installed successfully
“java -version”
You should be able to get the java version successfully.





 

 

 

 

 



How to install docker compose on EC2



******************************************
How to Install docker compose on EC2
******************************************



Here, we will see how to install the docker compose. 

1. Copy the appropriate docker-compose binary from GitHub:
sudo curl -L “https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose”

2.To get the latest version 
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose


3. Fix permissions after download:
“sudo chmod +x /usr/local/bin/docker-compose”

4. Verify if the docker compose successfully installed
“docker-compose version”




















To go to previous post, click on below link

How to install docker on EC2 instance



**************************************
How to install docker on EC2 instance
***************************************



To be continued,
This post will show how to install docker in the Ec2 server.

I have explained two ways here.

1. Install docker on EC2

8. Now let’s see how to install docker on an EC2 instance
    
1. Update the installed packages and package cache on your instance.
“sudo yum update -y”
    - Is this ok (y/d/N) : type ‘Y’ and enter

2. Install the most recent Docker.
“sudo yum install docker -y”

3. Check the docker status if the docker is active or inactive state
“sudo service docker status”

It shows the status as “Inactive(dead)”, That means docker service is not started yet.

4. To start the Docker service, run below command and check status again.
“sudo service docker start”
“sudo service docker status”

After running the above two commands docker service should start and in Active state(running state). To confirm check the below step

5. Let’s check the docker version and available images
“docker --version”


  To check the docker images, run below command.
  “sudo docker images”
  Obviously , there will not be any images running.

6. Add the ec2-user to the docker group so you can execute Docker commands without using sudo as prefix to any command.
“sudo usermod -a -G docker ec2-user”

Now let’s check docker images without using sudo command
“docker images”

Note - In case if you get ‘permission denied’ message because we need to restart ec2 instance so that the changes will of adding ec2-user to docker group changes will be reflected.

8. Restart EC2 instance
“sudo reboot”

9.Now login to ec2 instance again.
“ssh -i DockerisedSeleniumGrid.pem ec2-user@ec2_public_ip_address”

Now check docker images command without using sudo
“docker images”
Because docker service is not started yet, let’s start docker using below command
“sudo service docker start” and the check docke image "docker images". It should work.

10. Check any running container available
“docker ps -a”


Up till here, we have seen how to install docker on EC2. Now we need to install docker compose on EC2
Click on below to check how to do that.

After installing docker compose, We need to install the Java on EC2 in order to run the docker.
To check, click on below link


So far, We have EC2 instance ready and Docker and Java installed in it, Now we will configure selenium Hub and Node using docker-compose file
- This time we will launch EC2 using WinSCP, Download WinSCP
- Launch WinSCP
-Host name "Public ipv4 ip address" of Ec2
-User name as "ec2-user"
-Click on Advance
-
-Click on "OK" ->  Click on Login
-After completing the process user will be able to login to EC2 and see the below screen

- Create a file as I have created,
-Right click -> File -> name the file as docker-compose
-Double click on the file and paste the below content
- Login to Ec2 using command prompt as we did previously.-Envoke the docker-compose file using "docker-compose up"-You can access hu using "EC2 IP address:4445(Port)"
-And you can use the same URL in selenium RemoteDriver
-Selenium Hub will be triggered and Hub will delegate tests to respective node


2. Install docker on EC2

1) Create a AWS ec2 server 
2) $ sudo 
3) # apt-get update 
4) # curl -fsSL https:i!get.docker.com -o get-docker.sh 
5) # sh get-docker.sh 
6) # docker --version 
7) # docker run --name myc1 -d -p 8081:8080 <image name> 

To login to Ec2:

1) Go to the location where the pem file is downloaded
2) Right-click "git bash" (Git bash must be downloaded in the system)
3) You will be inside the Ec2 instance.





To go to previous post, Click here

 

Run Selenium tests on Dockerized Grid on EC2 step by step guide - Part 2

 

*******************************************
Run selenium test on Docker grid on EC2 server
*******************************************




To be continue,



- Select ‘Create new Key pair
- Type Key pair name ‘DockerisedASeleniumGrid
- Click on launch instance
- DockerisedASeleniumGrid.pem will be downloaded automatically to login to EC2 instance using SSH


- Success message
- That means EC2 instance successfully created


6. On EC2 dashboard you can see EC2 instance ID. I have provided name it as ‘Ec2_docker’



7. Now let’s login to EC2 instance using SSH
- Open command prompt
- Go to the location(download) where DockerisedSeleniumGrid.pem file is downloaded.
- Use below command
“ssh -i DockerisedSeleniumGrid.pem ec2-user@ec2_public_ip_address”

If you are able to see Amazon Linux 2 AMI, means you are successfully logged in to your server. - shown below


- Update packages using the command “sudo yum update”


We have successfully created and launch the EC2 successfully, Now our next job is to install docker on EC2. 
Check the below link



To go to previous post, click on below link
























Monday, August 1, 2022

Run Selenium tests on Dockerized Grid on EC2 step by step guide - Part 1




*******************************************
Run selenium test on Docker grid on EC2 server
*******************************************

It’s always being a challenging task to run parallel tests in selenium. To setup parallel run on a single machine we need to set up multiple VM’s which consumes so much memory and leads to problems like given below.
  • Makes test slow.
  • Leads to hanging browser sessions.
  • Sometimes browser crash.
To overcome this issue docker came into picture. Which is super easy solution of running selenium tests on a single machine using Docker.


Here Selenium Hub will be running(in docker) on our system and it will delegate tests to respective nodes. But why to maintain the selenium hub on local machine when we have AWS. So to make it more simpler. We are setting everything up on EC2 server itself. lets EC2 manage everything.

Follow the below steps:

1. Login to Amazon console using IAM user credentials

2. Type EC2 in search bar and Select EC2 option.



3. Select Instances option to check if there is any EC2 instance already running.
As you can see below, there is no instance is running.




4. So, let’s create a new EC2 instance. Click on ‘Launch instances




5. Now select Amazon Linux

- Under that Select "Amazon Linux AMI (HVM) of 64 Arch Server" which is marked as Free tier eligible.

Here, An Amazon Machine Image (AMI) is a master image for the creation of virtual servers -- known as EC2 instances -- in the Amazon Web Services (AWS) environment.


- Select Instance Type as T2.micro – free tier eligible
- Click on Launch Instance (Shown below)

Note – Select only free tier eligible otherwise other AMI type is paid which may cost you if you select other than Free tier eligible AMI.




To continue to next post, click on below link
 

Monday, March 29, 2021

What is Docker - Important to know about Docker for SDET


                             


Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. 
Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. Because all of the containers share the services of a single operating system kernel, they use fewer resources than virtual machines.


What is Docker?
Docker creates simple tooling and a universal packaging approach that bundles up all application dependencies inside a container which is then run on Docker Engine.

Docker Engine enables containerized applications to run anywhere consistently on any infrastructure, solving “dependency hell” for developers and operations teams, and eliminating the “it works on my laptop!” problem.

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.

Package Software into Standardized Units for Development, Shipment and Deployment


What is Container?
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

Container images become containers at runtime and in the case of Docker containers - images become containers when they run on Docker Engine. Available for both Linux and Windows-based applications, containerized software will always run the same, regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging.

Docker containers that run on Docker Engine:
Standard: Docker created the industry standard for containers, so they could be portable anywhere
Lightweight: Containers share the machine’s OS system kernel and therefore do not require an OS per application, driving higher server efficiencies and reducing server and licensing costs
Secure: Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry


Comparing Containers and Virtual Machines
Containers and virtual machines have similar resource isolation and allocation benefits, but function differently because containers virtualize the operating system instead of hardware. Containers are more portable and efficient.



CONTAINERS:
Containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Containers take up less space than VMs (container images are typically tens of MBs in size), can handle more applications and require fewer VMs and Operating systems.


VIRTUAL MACHINES:
Virtual machines (VMs) are an abstraction of physical hardware turning one server into many servers. The hypervisor allows multiple VMs to run on a single machine. Each VM includes a full copy of an operating system, the application, necessary binaries and libraries - taking up tens of GBs. VMs can also be slow to boot.



















Thursday, March 11, 2021

Most useful Docker commands for Automation tester

 













Docker command

Meaning

docker image pull selenium/standalone-chrome

 Here we are pulling chrome image

docker image ls

To list out the available/downloaded images

docker container create selenium/standalone-chrome

Here we are creating chrome container --it will return container id

docker container start containerID

To start container

docker container ps

To check whether container started or not

docker stop containerID

To stop the running container

docker stop containerID1 containerID2 containerID3

To stop the multiple running container at a time

docker restart containerID

To restart the container

docker images -f "reference=selenium/*:latest"

It will filter images starting with name ‘selenium’

/* - regular expression with latest version

docker ps

you can check the status whether the container is running or stopped

docker ps -a

It will show all the running containers

docker rm containerID

It will delete container

docker stop containerID1 containerID2 containerID3

It will delete multiple container at a time

docker rm imageID

It will delete image ‘imageID

docker inspect containerID

It will allow to inspect the container

docker kill containerID

It will terminate the running container

docker container run

It will pull, create and start the container by single command

docker run -p 4444:4444 selenium/standalone-chrome

It will map local port 4445 to docker port 4444

docker run -p 4444:4444 --name selgrid selenium/standalone-chrome

It will map local port 4445 to docker port 4444 with container name selegrid

docker run -d -p 4444:4444 --name selgrid selenium/standalone-chrome

It will map local port 4445 to docker port 4444 with container name selegrid and and all the process will be done in background

docker container --help

To seee the docker commands

docker exec –ti containerID  /bin /bash

It will allow you to take inside the container.

-t à indicate you want to see the output from the comd prompt

-I -àIndicate that you want to enter some input to cmd promt inside the container

 

 

How to run selenium test cases on Dockerised selenium grid (Traditional Approach)

Pre-requisites:

1. Download selenium/hub image

2. Download selenium/node-chrome-debug

3. Download selenium/node-Firefox-debug

docker run -d -p 4444:4444 --name selenium-hub selenium/hub:latest

or

 

docker run -d -p 4444:4444 - -restart always --name selenium-hub selenium/hub:latest

‘Docker run –d’ Running this docker container in back ground and ‘-p 4444:4444’ mapping the local port 4444 to selenium hub port 4444 and giving name

‘-  - name selenium-hub’ and creating container from ‘selenium/hub:latest’ with latest tag

docker logs containerID

To seee the logs

http://localhost:4444/grid/console

Hit the url in browser. You must see Hub created

Hub is created, Now our next task is to link chrome node to selenium hub

docker run –d - -link selenium-hub:hub selenium/node-chrome-debug:latest

 

or

 

docker run –d - -link selenium-hub:hub - -restart on-failure:3 selenium/node-chrome-debug:latest

Creating node and inking with selenium hub

‘docker run –d’ – To run the command in background

‘- -link selenium-hub:hub’ – linking with selenium hub with name ‘selenium-hub’ which is acts as hence giving name as hub ‘:hub’

‘selenium/node-chrome-debug:latest’ – linking with node with latest tag

http://localhost:4444/grid/console

Refresh the browser and you must be able to see chrome node created with version

Similarly, Now link firefox node to selenium hub

docker run –d - -link selenium-hub:hub selenium/node-firefox-debug:latest

 

or

 

docker run –d - -link selenium-hub:hub - -restart on-failure:3 selenium/node-firefox-debug:latest

Creating node and inking with selenium hub

‘docker run –d’ – To run the command in background

‘- -link selenium-hub:hub’ – linking with selenium hub with name ‘selenium-hub’ which is acts as hence giving name as hub ‘:hub’

‘selenium/node-firefox-debug:latest’ – linking with node with latest tag

http://localhost:4444/grid/console

Refresh the browser and you must be able to see firefox node created with version

Here we have created two node – if you have to connect again one firefox or chrome node, simply run

docker run –d - -link selenium-hub:hub selenium/node-firefox-debug:latest

http://localhost:4444/grid/console

Refresh the browser and you must be able to see three node 1 chrome node and 2 firefox

 

 

Container Restart policy-

Suppose you are executing test suit of 100 test cases and at 5th test case your Container got crashed in that

case all rest of the test cases will be failed. In this scenario, restart policy is very important and good practice.

 

No(Default)

This is default flag

On Failure

When container crashes then only docker daemon will restart the container

Always

Container will restart always unless docker daemon stopped

Unless-stopped

Restart always until manually stopped

How to update container with restart policy

docker update - -restart on-failure:2 containerID

Restart policy will be applied to particular container ,

It is updating a container with restart policy on failure 2 times

docker inspect containerID

you can check the container restart policy by

inspectin git

 

 

How to run selenium test cases on Dockerised selenium grid- Docker Compose file

Pre-requisites:

1.      Create docker-compose.yaml file in eclipse

2.      Open command promt

3.      Go to docker-compose file

4.      Entre below commands

docker-compose up

or

docker-compose up -d

It will execute compose file with extension .yaml, also you can see the logs

It will run in background

docker-compose –f selenium-compose.yaml up

Or If your docker compose file name is different, you can us can use this command

docker-compose down

It will stop your compose file

docker-compose ps

To see what an all serices and container there in docker compose file

docker-compose scale chrome=5

It will create 4 new chrome instances as 1 is already there in compose file.

Chrome –it Is service name in docker-compose file

 

 

 

Refer docker-compose file

version: "3"

services:

  selenium-hub:

    image: selenium/hub:latest

    container_name: selenium-hub

    restart: always

    ports:

      - "4444:4444"

  chrome:

    image: selenium/node-chrome-debug:latest

    volumes:

      - /dev/shm:/dev/shm

    depends_on:

      - selenium-hub

    environment:

      - HUB_HOST=selenium-hub

      - HUB_PORT=4444

    restart: on-failure:3

  chrome_79:

    image: selenium/node-chrome-debug:3.141.59-zinc

    volumes:

      - /dev/shm:/dev/shm

    depends_on:

      - selenium-hub

    environment:

      - HUB_HOST=selenium-hub

      - HUB_PORT=4444

    restart: on-failure:3

  firefox:

    image: selenium/node-firefox-debug:latest

    volumes:

      - /dev/shm:/dev/shm

    depends_on:

      - selenium-hub

    environment:

      - HUB_HOST=selenium-hub

      - HUB_PORT=4444

    restart: on-failure:3 

 

Real time Dashboard:

Important Link:

Getting started with elastic search

Download Elasticsearch

Install elastic search with docker

Environment variable configuration

Docker hub - elasticsearch

 

Docker command

docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.11.1

To run elastic search

http://localhost:9200/

To check elastic search is up and running

docker run -p 5601:5601 --name kibana --link elasticsearch:elasticsearch docker.elastic.co/kibana/kibana:7.11.1

To run Kibana

http://localhost:5601/

To check elastic search and kibana is up and running

 


Once elastic search is up and running, you can push your data to elastic search as shown below

URI - http://localhost:9200/world/countries

End point - http://localhost:9200/
Index – world
Type - countries

To see data in elastic, download chrome extension for elastic search:
1. Type elastic search chrome extension in google
2. Install ‘Elastic search head’ the extension
3. Launch the extension by clicking on elastic search head extension

You can see all your data in elastic using its extension.

 

 

***Manager your Docker container using Portainer 

docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer

To run portainer

http://localhost:9000/

To check portainer is up and running

 

Setup Selenoid in docker

 

 

 

 

 

 

How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post