using environmental variable & Creating multi-container architecture using link & Implementing Lamp Architecture using Docker, Creating CI-CD Environment using Docker

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

To start mysql as container, open interactive terminal in it, create a sample table.

docker run –name mydb -d -e MYSQL_ROOT_PASSWORD=sunil mysql:5

docker container ls

I want to open bash terminal of mysql

docker exec -it mydb bash

To connect to mysql database

mysql -u root -p

enter the password, we get mysql prompt

TO see list of databases

show databases;

TO switch to a databse

use db_name
use mysql

TO create emp tables and dept tables

exit

exit

exit


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

Multi container architecture using docker

This can be done in 2 ways
1) –link
2) docker-compose

1) –link option

Use case:

Start two busybox containers and create link between them

Create 1st busy box container

docker run –name c10 -it busybox

/ #

How to come out of the container without exit
( ctrl + p + q)

Create 2nd busy box container and establish link to c1 container

docker run –name c20 –link c10:c10-alias -it busybox ( c10-alias is alias name)

/ #

How to check link is established for not?

/ # ping c1

Ctrl +c ( to come out from ping )

( ctrl + p + q)
+++++++++++++++++++++++++++++++++

Ex 2: Creating development environment using docker

Start mysql as container and link it with wordpress container.

Developer should be able to create wordpress website

1) TO start mysql as container

docker run –name mydb -d -e MYSQL_ROOT_PASSWORD=sunil mysql:5

( if container is already in use , remove it

docker rm -f mydb )

Check whether the container is running or not

docker container ls

2) TO start wordpress container

docker run –name mysite -d -p 5050:80 –link mydb:mysql wordpress

13.232.183.233:5050

Check wordpress installed or not
Open browser
public_ip:5050
18.138.58.3:5050

++++++++++++++++++++++++++++++++++++++++++++++
Ex 3: Create LAMP Architecture using docker

L — linux
A — apache tomcat
M — mysql
P — php

( Linux os we already have )

Lets remove all the docker containers

docker rm -f $(docker ps -aq)

docker container ls ( we have no containers now )

1) TO start mysql as container

docker run –name mydb -d -e MYSQL_ROOT_PASSWORD=sunil mysql:5

2) TO start tomcat as container

docker run –name apache -d -p 6060:8080 –link mydb:mysql tomee

TO see the list of containers

docker container ls

To check if tomcat is linked with mysql

docker inspect apache ( apache is the name of the container )

3) TO start php as container

docker run –name php -d –link apache:tomcat –link mydb:mysql php

++++++++++++++++++++
Ex 4:
Create CI-CD environment, where jenkins container is linked with two tomcat containers.

Lets delete all the container

docker rm -f $(docker ps -aq)

To start jenkins as a container

docker run –name devserver -d -p 7070:8080 jenkins/jenkins

to check jenkins is running or not?
Open browser
public_ip:7070
http://18.138.58.3:7070

We need two tomcat containers ( qa server and prod server )

docker run –name qaserver -d -p 8080:8080 –link devserver:jenkins tomee

to check the tomcat use public_ip but port number will be 8080
http://18.138.58.3:8080

docker run –name prodserver -d -p 9090:8080 –link devserver:jenkins tomee

to check the tomcat of prodserver
http://18.138.58.3:9090

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

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

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

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

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