Creating testing environment using Docker & GUI Based Containers, Installing & Examples Docker Compose.

Creating testing environment using Docker – 

Docker allows you to run your tests in containers as well as isolate your tests in development and deployment. 

Creating testing environment using docker

Create selenium hub container, and link it with two node containers.
One node with firefox installed, another node with chrome installed.

Tester should be able to run selenuim automation programs for testing the application on multiple browsers.

To delete all the running containers

docker rm -f $(docker ps -aq)

In Browser — open – hub.docker.com

Search for selenium
We have a image – selenium/hub

To start selenium/hub as container

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

In hub.docker.com
we also have- selenium/node-chrome-debug ( It is ubuntu container with chrome)

To start it as a container and link to hub ( previous container)

docker run –name chrome -d -p 5901:5900 –link hub:selenium selenium/node-chrome-debug

In hub.docker.com
we also have- selenium/node-firefox-debug

To start it as a container and link to hub ( It is ubuntu container with firefox)

docker run –name firefox -d -p 5902:5900 –link hub:selenium selenium/node-firefox-debug

To see the list of container

docker container ls

Note: firefox and chrome containers are GUI containers.

To see the GUI interface to chrome / firefox container

Download and install vnc viewer
In VNC viewer search bar
public_ip_dockerhost:5901

18.136.211.65:5901
Password – secret

++++++++++++++++++++++++++++++++++++++++++++++++++++++

All the commands we learnt till date are adhoc commands.

In the previous usecase we have installed two containers ( chrome and firefox)
Lets say you need 80 containers?
Do we need to run 80 commands?

Instead of 80 commands, we can use docker compose

++++++++++++++++++++++++

Docker compose
This is a feature of docker using which we can create multicontainer architecture using yaml files. This yaml file contains information about the containers that we want to launch and how they have to be linked with each other.Yaml is a file format. It is not a scripting language.
Yaml will store the data in key value pairs
Lefthand side – Key
Righthand side – Value
Yaml file is space indented.

Sample Yaml file


logiclabs:
trainers:
sunil: Devops
raj: Python
Coordinators:
lakshmi: Devops
rani: AWS

++++++++++++++++++++++
logiclabs — root element
+++++++++++++++++++++++++

To validate the abvove Yaml file
Open http://www.yamllint.com/
Paste the above code — Go button

++++++++++++++++++++++++++

Installing Docker compose

1) Open https://docs.docker.com/compose/install/
2) Go to linux section
Copy and pase the below two commands

sudo curl -L “https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

How to check docker compose is installed or not?

docker-compose –version

+++++++++++++++++++++++++

+++++++++++++++++++++++++

Lets remove all the running container

docker rm -f $(docker ps -aq)

To stop the containers

docker-compose stop

We got lot of logs coming on the screen. to avoid it we use -d option

Create a docker compose file for setting up LAMP architecture

vim docker-compose.yml


version: ‘3’

services:
mydb:
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: sunilsunil

apache:
image: tomee
ports:

  • 6060:8080
    links:
  • mydb:mysql php:
    image: php
    links:
  • mydb:mysql
  • apache:tomcat

:wq

docker-compose up -d

To see the list of the containers

docker container ls

( Observation – we are unable to see the php container)

docker ps -a

++++++++++++++++++++++++++++++++++++
Ex: Docker-compose file for setting up CI-CD Environment.
jenkins container is linked with two tomcat containers

vim docker-compose.yml


version: ‘3’
services:
devserver:
image: jenkins/jenkins
ports:

  • 7070:8080 qaserver:
    image: tomee
    ports:
  • 8899:8080
    links:
  • devserver:jenkins prodserver:
    image: tomee
    ports:
  • 9090:8080
    links:
  • devserver:jenkins

:wq

docker rm -f $(docker ps -aq)

docker-compose up -d

docker container ls

To check
public_ip:7070 ( To check jenkins )
public_ip:8899 ( Tomcat qa server )
public_ip:9090 ( Tomcat prod server )

13.126.58.183:7070
13.126.58.183:8899
13.126.58.183:9090
+++++++++++++++++++++

Docker-compose file to set up testing environment.
selenium hub container is linked with two node containers.

vim docker-compose.yml


version: ‘3’
services:
hub:
image: selenium/hub
ports:

  • 4444:4444 chrome:
    image: selenium/node-chrome-debug
    ports:
  • 5901:5900
    links:
  • hub:selenium firefox:
    image: selenium/node-firefox-debug
    ports:
  • 5902:5900
    links:
  • hub:selenium

:wq

Lets delete all the running containers

docker rm -f $(docker ps -aq)

docker-compose up -d

docker container ls

As it is GUI container,
we can access using VNC viewer

Open VNC viewer
52.77.219.115:5901
password: secret

++++++++++++++++++++++++++++++++++++++++++++++

Leave a Comment

MFH IT Solutions (Regd No -LIN : AP-03-46-003-03147775)

Consultation & project support organization.

Contact

MFH IT Solutions (Regd)
NAD Kotha Road, Opp Bashyam School, Butchurajupalem, Jaya Prakash Nagar Visakhapatnam, Andhra Pradesh – 530027