Sunday, September 6, 2020

Docker

Docker supporting urls
  https://docs.docker.com/
  https://hub.docker.com/

Docker is all about speed
 Develop Faster
 Build Faster
 Test Faster
 Deploy Faster
 Update Faster
 Recover Faster


Docker process
a. Create a DockerFile . for which we have a set of guidelines of how to create a Dockerfile
b. Build the Image from DockerFile. For which we will be using a command
c. Multiple containers are created from the image. For which we will be using commands

Docker was released on March 2013 and every year they have conference on Mar.

Referral URL  --> https://landscape.cncf.io/

Docker CE (Community Edition) --> Free
Docker EE (Enterprise Edition)  --> Paid

Three major types of installs
   Direct
   Mac/Win
   Cloud

 Linux (different per distro) (don't use default package which is available in the Linux OS)
 Docker for windows(or legacy Docker Toolbox)
 Docker for MAC (or legacy Docker Toolbox)
 Docker for AWS/Azure/Google for cloud

Rasberrypi , Mainframe , Windows, Mac and Linux support Docker after 2016

Stable vs Edge version

In Docker world Edge means Beta version and it is supported for 1 month until the next beta/Edge version comes. Edge is released monthly.

Stable Version   is released Quarterly  and supported for four months.

EE supported for longer which would be like 1year minium and it is paid version which will be used by enterprise .

If we don't want to install docker on local machine then we can use the below URL but we can use it for 4hrs only .In short the URL is referred as PWD (Play With Docker)

https://labs.play-with-docker.com

When I started the docker server it took long time 

Below screen shot shows the message which we got when the docker server was not running and when it was running




Docker on Windows : 

Two types of container  
    Linux Container
    Windows Container
Windows Serer 2016 also supports Windows Containers
Uses Hyper-V with tiny Linux VM for Linux Containers
Powershell native

Docker of Windows 7/8 and 10 Home 
    Uses Docker Toolbox not as fancy as Docker for Windows
    Like others, download at stored.docker.com
    Runs a tiny Linux VM in VirtualBox via docker-machine
    Uses abash shell to make it more like Linux options
    Does not support Windows container

Docker on Windows Server 2016
   Windows server 2016 supports native windows Containers
    "Docker for Windows" runs on Win2016 but not required
        Only do this for when you run Win 2016 locally for dev/test. NOT for prod
    No options for previous Windows Server versions
    Hyper-V can still run Linux VMs(that can run docker) just fine

From Sep 2020 we see WSL2 (Windows Subsytem Linux) can also be used instead of Hyper -V to start docket in windows 10 pro

We can use Visual Studio code with Docker extension as editor
we can use cmder (https://cmder.net/) as our command editor

Docker on Linux
Three main ways to install
   script
   store
   docker-machine

get.docker.com script(latest edge release)
   curl -sSL https://get.docker.com/ | sh
store.docker.com has instructions for each distro. (Debain, Red hat , Fedrora are major distribution in Linux)
RHEL (Red Hat Enterprise Linux ) only supports Docker Enterprise Edition, but CentOS will work.
Installing in a VM,Cloud instance , all are the same process


Docker changes to release cycle , product name and versioning

In 2017 docker versioning,release cycle and product names changes but features haven't. the url has more details  https://docker.com/blog/docker-enterprise-edition/
Like Ubtunu version docker also started to use the version named as YY.MM

Docker Engine(the free one we all know and love) is now Docker CE (Community Edition). Notice the drop of the word Engine.I suspect we can just call this docker now. It includes the cli client and backend daemon/service and api. daemon is a background process running in linux world. service mightbe a background process running in windows world.

Docker Data Center is now Docker EE(Enterprise Edition) and adds additional paid products and support on top of docker in three pricing tiers.

These changes don't affect Docker compose or docker Machine.

Docker version is now YY.MM based, using the month of its expected release and the first one will be 17.03.0, which is the first point of release of the 17.03 release. If any bug/security fixes are needed to that release, the first update will be 17.03.1 etc.


Docker commands 

To get the docker version we have following options
    docker version
    docker -v
    docker --version
To get the info of docker use the below command
    docker info

To get the list of docker commands and Management commands just type
     "docker"
Since the commands in docker are increasing, docker has organized them into Management so earlier to 2017 we used "docker run" now it will be "docker container run". If we want to use the old way it is fine for old commands but when a new command is introduced it will work only in the new format 

Old style for command in docker 
        docker <<command>> (options)
New style for command in docker 
       docker <<management command>> <<command>> (options)

To get the list of commands under a management then give the command as 
      docker <<management command>> --help
      docker container --help
      docker builder --help

To get help about the command then use the below
   docker <<management_command>> <<command>> --help
   docker container <<command>> --help
   docker image <<command >> --help

Image Vs Container

      An Image is the application we want to run.
     A container is an instance of that image running as a process
     You can have many containers running off the same image.
     Nginx is web server and we will use that as our image.
     Docker's default image "registry" is called Docker Hub (hub.docker.com)
   


docker container run is used to start a new container from an image.The image repository will be docker hub.

docker container run --publish 80:80 nginx
 a. The command looked for nginx locally in image cache but since it did not find it
       so it downloaded the latest version of nginx from docker hub.
 b. Created a new container from that image and prepares to start.
 c.  Left number is the host port and we have opened port 80 on the host IP .
 d. Routes that traffic to container IP, port 80 which is the right number.
     In the container no other port will be opened expect 80.
e. Starts container by using the command specified in the docker image file.

docker container run --publish 9080:80 --detach ngnix 
                                      or
docker container run --p 9080:80 --d ngnix
         Used to create new container from the image and run the container in background
docker container run --publish 9080:80 --detach --name pavan_webhost ngnix 
         Used to create new container from the image with a name "pavan_webhost" and run it in background.
docker container stop <<container ID>>/<<container_name>>
    Used to stop the container with the container ID
docker container logs pavan_webhost 
    Used to list the logs of the container with name pavan_webhost
docker container ls
    Used to list the currently running containers.
docker container ls -a
    Used to list all containers  which are running and stopped
docker container rm -f <<container ID>>
    Used to remove one or more container forcefully even it is running
docker container rm <<container ID>>
      Used to remove one or more container which are in stopped state. To remove multiple the specify
      container ID separating with space.
docker container top <<container_name>>  
          Used to know what process are running in container
docker container stats
        Used to know the performance stats of the container which are running
docker container inspect <<container_name>>
       Used to know the container config

docker container run -d --network <<network name>> --network-alias <<alias-name>> <<imagename>>
                                            or
docker container run -d --net <<network name>> --net-alias <<alias-name>> <<imagename>>
 Used to run the container in background and attach to network and have network alias sapecified
    Eg:
           docker container run -d --net dude --net-alias search elasticsearch:2

If we want to connect to the container for doing some configuration then we can use the following command

     docker container exec -it <<container_name>> bash
     docker container exec -it mysql_db bash
    docker container exec -it mysql_db sh

    docker container exec -t -i mysql_db sh
    docker container exec -t -i mysql_db bash

Note -it is not a single option it is actually to -t and -I. 
Incase if the Linux distro is not having bash then use sh

Start vs Run 
   
Run is used to create a new container from the image every time.
Start is used to start existing container which is stopped.

Container vs VM
  VM and Containers have similarities but they are different.
  Containers aren't Mini-VM's
  Containers are just processes
  Limited to what resources Container can access
  Containers Exit when process stops
 

To pull details about image we have Management command called image

docker image pull <<imagename>>
     To pull image from

docker image ls 
   to list the image which we have locally

docker image inspect <<imagename>>
   To list detail information of one or more image

docker image history <<imagename>>
   To show the history of an image

Whats in an Image(and what isn't)
   Application binaries and dependencies
   Metadata about the image data and how to run the image
   Official definition: "An Image is an ordered collection of root filesystem changes
                                   and the corresponding execution parameters for use within
                                    a container runtime"
   Not a complete OS. No kernel, kernel modules(e.g. drivers)
   Small as one file (your app binary) like a golang static binary
   Big as Ubuntu distro with apt, and Apache, PHP and more installed

Image have Tags which is used to identify the version.
Alpine is small when compared to Debain distribution of Linux.


Image Layers

Docker uses UnionFilesystem mechanism


Docker Networks Default

Each container connected to a private virtual network which is called as "bridge network"
Each virtual network routes through NAT firewall on host IP
All containers on a Virtual network can talk to each other without -p
Best practice is to create a new virtual network for each app:
   network "my_web_app" for MySQL and php/apache containers
   network "my-api" for mongo and nodejs containers
Make new virtual networks
Attach containers to more than one virtual network (or none)
Skip virtual networks and use host IP(--net=host)
Use different Docker network drivers to gain new abilities
Batteries Included , But Removable
  Default work well in many cases but easy to swap out parts to customize it


To work on network concept in Docker we have management command called network.

Show networks
      docker network ls
Inspect a network
     docker network inspect <<network name>>
     Eg: 
        docker network inspect bridge
Create a network and we can specify customer driver but the default is bridge
   docker network create --driver
   docker network create <<networkname>>
  docker network create my_app_net --> will create a new network with different subnet
Attach a network to container
     docker network connect
Detach a network from
   docker network disconnect

Docker DNS
  Understand how DNS is the key to easy inter-container communication
  See how it works by default with custom networks
  Learn how to use --link to enable DNS on default bridge network
  Docker daemon has a built-in DNS server that containers use by default
  Docker defaults the hostname to the container's name, but you can also set aliases

Best Practices
  Static IP's and using IP's for talking to containers is an anti-pattern, do your best to avoid it.

Creating Images/Docker file 
    To create an image basing on the Dockerfile we need to understand the stanza specification and below are the few and for more details look into the docker documentation (http://docs.docker.com/engine/reference/builder/). DockerFile is read from Top to bottom.

When creating Dockerfile make sure the least changeable are present at the top. When we are building the image from the Dockerfile if the compiler identifies a change then it will try to regenerate or recompile from that step to the bottom. While compiling the DockerFile it uses cache mechanism and SHA when  there is no change and it can skip that step.

We can also have multiple images from a DockerFile.

    FROM
    RUN
    CMD
    LABEL
    EXPOSE -- The ports that needs to be exposed 
    ENV
    ADD
    COPY
    ENTRYPOINT
    VOLUME   -- To store the data of the image during runtime.
    USER
    WORKDIR
    ARG
    ONBUILD
    STOPSIGNAL
    HEALTHCHECK
    SHELL
   
   
    
    Container Lifetime & Persistent Data

       Containers are usually immutable and ephemeral.
       To persistent data in Container we have two ways 
             Volumes
              Bind Mounts
       Volumes : Make special location outside of container UFS(Union Filesystem)
       Bind Mounts: Maps a host file or directory to a container file or directory like file sharing
       
    Volumes

To know the command of volume 
    docker volume --help
 To list the volumes
   docker volume ls 
To remove the volumes which are not used by containers 
   docker volume prune
   
The command is used to name a volume and we can also reuse this volume for other container as well
docker container run -d --name mysqlvolume -e MYSQL_ALLOW_EMPTY_PASSWORD=true -v mysql-db:/var/lib/mysql  mysql

docker container run -d --name mysqlvolume2 -e MYSQL_ALLOW_EMPTY_PASSWORD=true -v mysql-db:/var/lib/mysql  mysql

Now mysqlvolume and mysqlvolume2 are going to use the same volume

Bind Mounting

   Maps host file or directory to a container file or directory
   Basically just two locations pointing to the same files(s)
   Again , skips UFS and host files overwrite any in container
   Bind Mounting are host specific so we cannot mention in the Dockerfile, must be at container run
   … run -v //c/users/bret/stuff:/path/container (Windows)
   … run -v /Users/bret/stuff:/path/container( mac/Linux)




Docker Compose
   Configure relationships between containers
   Save our docker container run settings in easy-to-read file
   Create one-liner developer environment startups
   Comprised of 2 separate but related things
 
               1. YAML (docker-compose.yml) formatted file that describes our solution options for
                         containers
                         networks  
                         volumes
                         images
                         Environment variables
               2. CLI tool docker-compose used for local dev/test automation with those YAML files
               
                       
 


*******************************************************************
How to create a image ?
How have the dependencies of the image?








Mongodb

Terminology and Concepts

If you're not familiar with MongoDB, here's a quick translation cheat sheet to get you familiar with the terminology.
SQL ServerMongoDB
DatabaseDatabase
TableCollection
IndexIndex
RowDocument
ColumnField
JoiningLinking & Embedding
PartitionSharding (Range Partition)
ReplicationReplSet


RDMS

MongoDB

Database

Database

Table

Collection

Row/Tuple

Document

Column/Attribute/Variable

Field

Table Join

Embedded Documents

Primary Key

Primary Key(Default key _id  provided b mongodb itself)

Database Server and client

Myqsld/Oracle

Mongod

Mysql/sqlplus

mongo


In Mongodb Primary key is mandatory and _id is the field which used for primary key. In RDBMS  we can have table with out primary key

Default port fro mongodb is 27017

To start mongodb server use the below command . Below command will have the data path mentioned
       mongod -dpath c:\pavan\custom_data

No SQL

Categories of NoSQL Database 


    Key-Value Stores :   This is simplest and fastest in NoSQL 
           Eg : Redis, Memcached, Coherence
    Wide Column Stores(Tabular) :  Due to normalization we will see performance issue in RDBMS .  
                                                          When we use  joins the select queries will be slow.
        Eg:   HBase, Cassandra,Big Table
    Graph Store :    To show the hierarchy this will be used like employee hierarchy in an organization to 
                                 fetch this in RDBMS it going to be a costly Query as it use self join to the same table
        Eg: Neo4J , HyperGraphDB, Oracle NoSQL
    Document Base : Special type of formatted string like JSON. In JSON format we have Key value
        Eg:   Mongodb, CouchDB, cloudant


https://db-engines.com/en/ranking/key-value+store


Entity

SQL databases

NoSQL Databases

Type

One Type(SQL) with Minor Variation

Many Types(Document,Key-value,Tabular,Graph)

Development

1970

2000

Examples

Oracle, SSQL, DB2 etc

MongoDB,Cassandra, Hbase, Neo4J

Schema

Fixed

Dynamic

Scaling

Vertical

Horizontal

Dev Model

Mix

Open source

Consistency

Follow ACID

Follow BASE



ACID - Atomic, Consistent,Isolated, Durable

CAP Theorem -  Consistency , Availability , Partition Tolerance

CA (Consistency and Availability) : RDMS (Oracle,MySQL,MircoosftSQL,DB2)
CP (Consistency and Partition Tolerance) : Mongodb, HBase, Redis
AP(Availability, Partition Tolerance ): CouchDB, Cassandra,DynamoDB,Riak

BASE  : Basiclly Available, Soft State, Eventual Consistency

SQLITE

 SQLITE : SQLite is a relational database management system (RDBMS) contained in a C library. In contrast to many other database management systems, SQLite is not a client–server database engine. Rather, it is embedded into the end program.  (https://en.wikipedia.org/wiki/SQLite)


https://sqlite.org/cli.html


Installing SQLite 

    Step 1 : https://www.sqlitetutorial.net/download-install-sqlite/

    step  2 : https://www.tutorialspoint.com/sqlite/sqlite_installation.htm

Saturday, September 5, 2020

Heli ALM DB

 SCMCHGLST --> Table contains changelist associated to the work item type like Requirements , Defect , Testcases 

        EntityType = Type of the work item   

                    1920036212 --> Task is the entity type 

                    1684431732 --> Defect is the entity type

        attachDate = Date on which the changeset and Entitytype are tied up

        EntityyRID =    is the entity Id from table REQMNT ,Defect and Testcase


REQMNT  --> All requirements are stored and custom requirement type created in ALM as well


SCCFILE --> List the files associated to a entity type (Task, defect)

     ChangeType --> File change type like  (0- Files are directly linked, 1 - Add, 2 - update,3- delete )

                               Rename is also treated as like update 

      ChgLstID   --> is the foreign key from SCMCHGLST table and column is idRecord

      EntityRID  --> is the entity Id from table REQMNT ,Defect and Testcase