Docker

intro,  hub.docker.com (username = aziz27uk or aziz27uk@yahoo.co.uk, pass : Y......!
Docker installation: Windows, Linux, user permission,  Link two containers
Docker Host, Client, Images, Container, Daemon, Commands,  wordpress and mysql link
create container tomcat, jenkins, ubuntu, nginx, httpd, mysql,  CICD tier3 architecture (jenkins, tomcat, tomcat) (dev, test, prod)
multi container link, --link, Docker Compose,  jenkins master and slave,
 Deploy tomcat with docker compose, LAMP Architecture,
Deploy wordpress and mysql with docker compose, Testing environment with selenium hub
Deploy jenkins master / slave with docker compose, Simple Docker Volume, Sharing docker volume/volume container,
LAMP Architecture with docker compose, volume cotainer,
CICD environment with docker compose, docker custom image: docker commit, docker file, scenario1, scenario2, scenario3(cache Busting), scenario4,
Docker Registry, Image Layers,
Docker swarm,  

Docker Introduction:

 

sanjay quality thought sunil intelliqit
    Intro and installation  intro and installation on windows
    Important commands, image, container, etc  Installation on linux and imp commands
       mysql-wordpress-jenkins installation
       link command and 3 tier architect setup
       CICD 3 tier setup
       
       
       

 

Docker Installation on Windows:

Docker installation on Linux: Ubuntu (www.get.docker.com)

User permission to access docker:  Assgine a user permission to access docker or run docker commands.

Docker Images:

Docker Container

Docker Host: The host o/s on which docker is installed is called docker host.

Docker Client:Terminal which is used to access docker is called docker client, when you install docker a docker client is also installed and it runs in the background,  which is responsible for taking commands and pass it to another background process called daemon. 

Daemon: Daemon will analyse the type of command and route it to the following.

Docker Commands:

Container
docker run image_name To create a container
options used with run command  
--name give a name to container
-it open interactive terminal in the container
-d running container in detached mode
-e pass an environment variable
-v attach an external directory or device as a volume
--volume-from sharing volumes between containers
-rm delete a container on exit
-p port mapping , container port with host port, ex -p 8080:80 (8080 is host port)
-P capital P, used for automatic port mapping, container port mapped with host port greater than 30000
--link linking of containers
ctrl+p, ctrl+q To come out of a running container without exit
docker container ls list of running container
docker container ps -a List of all containers including running and stopped container
docker start cont_name / cont_id To start a stopped container
docker stop cont_name / cont_id To stop a started container
docker stop $(docker ps -aq) To stop all running containers
docker restart cont_name / cont_id To restart a container
docker restart -t 10 cont_name / cont_id To restart after 10 seconds
docker rm cont_name / cont_id To delete a stopped container
docker rm -f cont_name / cont_id To delete a running container forcefully
docker rm  $(docker ps -aq) To delete all stopped containers
docker rm -f $(docker ps -aq) To delete all running and stopped containers
docker inspect cont_name / cont_id To get detailed information about container
docker logs cont_name / cont_id To get logs of a container
docker port cont_name / cont_id To view ports open on a container
   
   
   
Image
docker image --help help on image command
docker pull Image_name Download a docker image
docker search image_name search a docker image
docker list images
docker image ls
List of all docker images
docker push image_name
docker push image_Id
Upload docker image
docker rmi image_name Delete a single docker image
docker system prune -a Delete all images
docker commit container_name/container_id image_name To create a docker image from container
docker build -t image_name . To create a docker image from dockerfile
docker inspect image_name get detailed information of image
docker image save image_nae tarfile_name To save an image as tar file
docker image load tarfile to extract an image from tar file
   
 
   

Create Container: Two step process, one step process

Tomcat installation: two step process

Jenkins:

Step1: #docker pull jenkins/jenkins (The jenkins image has been deprecated for over 2 years in favor of the jenkins/jenkins:lts image provided and maintained by the Jenkins Community as part of the project's release process. Use image:>docker pull jenkins/jenkins>docker run -p yourportNo:8080 --name=jenkins-master -d jenkins/jenkins)

Step2: #docker run --name myjenkins -p 9090:8080 -d jenkins/jenkins

Step3: access jenkins: http://publicIP:9090

Step4: Recover password : more details click here.

One Step Process:  If image is not present locally then it  download image and create container.

Ubuntu: -it (interactive mode) can be used with o/s, it creates ubuntu container and get into ubuntu terminal.

nginx: create container and assing port automatically using -P (capital P) in detach mode and pull image.  Port mapping is done for appications which can be access through browser.

 httpd: Apache Webserver

 mysql: It required environment varibale

Multi container link: Linking between containers can be done by

  1. docker --link
  2. docker compose
  3. docker networking
  4. python script

docker  run --link: create two containers (busybox, it is an linux o/s flavour) and create link between them.

Scenario 1:

Scenario 2: create a Development Environment for a wordpress container with mySQL database,

Scenario3: Create CICD 3 tier architecture environment in docker container.

 

 

Error: Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists or 404 error 

Resolve:

Scenario 4: Create jenkins master and jenkins slave: Refer here

 

LAMP Architecture:

LAMP Architecture Lab:

Testing environment with selenium hub: Create selenium hub container, and link it with two node containers(chrome and firefox etc..).

Note: Containers with firefox and chrome are GUI containers. To see the GUI interface to chrome / firefox containers install VNC viewer and access these containers with hostpublicIP:port

 

 

Docker Compose

Deploy a tomcat container with docker compose:

Deploy a mysql and wordpress and link each other with docker compose:

Depoy Master / Slave of jenkins through docker-compose:

Deploy LAMP architecture with docker compose:

L: Linux
A: Appliction Development( php)
M: Backend Database (MySQL)
p: Application Server (Apache Tomcat)

Linux is already installed on AWS instance or docker host, install docker and docker compose on docker host, create a yaml file to deploy php, mysql and apache tomcat.

#vim lamp.yml

---
version: '3'

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

 apache:
   image: tomee
   ports:
    - 6060:8080
   links:
    - mydb:mysql


  php:
   image: php:7.1-apache
   links:
    - mydb:mysql
    - apache:tomcat
...

Deploy CICD environment using docker compose where jenkins container linked with two tomcat containers.

Docker volume:

  1. Simple Docker Volume
  2. Docker volume container (sharable)

 

Simple Docker Volume:

Sharing the volume between different containers:  we have created docker volume and it will shared with other containers

Create another docker container sharing the same volume:

connect to myubuntu or myubuntu1 or myubuntu2 and you will get all files in the volume as volume is shred among them, and you will see all files aziz11..... abdul11.....mohammed11......   these files are stored in /ubuntuvolume and will be available in all shared volume.

Before deleting docker containers get the path from myubunt as its volume has been shared, By using path you can retrieve data.

Create volume container/sharable volume container:This volume should be attached with container which has some data.

Docker custom image:  Custom image can be created with the following methods:

  1. Docker commit command
  2. Docker file

Docker Commit: You create an image of an existing docker container with all software/application installed so it can be used later to create container.

Docker file: It is a smiple text file in which you define the following keywords(case sensitive):

  1. FROM: Used to specify the base image from which the docker file has to be created.
  2. MAINTAINER: This represents name of the organization or the author who created this docker file.
  3. CMD: This is used to specify the initial command that should be executed when the container starts.
  4. ENTRYPOINT: Used to specify the default process that should be executed when container starts. It can also be used for accepting arguments from the CMD instruction.
  5. RUN: Used for running linux commands within the container. It is generally helpful for installing the software in the container.
  6. USER: Used to specify the default user who should login into the container.
  7. WORKDIR: Used to specify default working directory in the container.
  8. COPY: Copying the files from the host machine to the container.
  9. ADD: Used for copying files from host to container, it can also be used for downloading files from remote servers.
  10. ENV: Used for specifying the environment variables that should be passed to the container.
  11. EXPOSE: Used to specify the internal port of the container.
  12. VOLUME: Used to specify the default volume that should be attached to the container.
  13. LABEL: Used for giving label to the container.
  14. STOPSIGNAL: Used to specify the key sequences that have to be passed in order to stop the container.

Scenario1: create a custom image of nginx.

  1. Create a dockerfile by taking nginx as the base image(image from docker hub) and specify the maintainer as aziz.
    1. $ sudo su -
    2. # vim dockerfile
    3. FROM nginx
      MAINTAINER aziz
    4. :wq!
  2. Construct an image from the above dockerfile.
    1. #docker build -t aziznginx .  ( t stands for tag, . stands for current working dir aziznginx is the new image name )

Scenario2: create a custom image of ubuntu and git

 

Scenario3: cache busting

create a docker file and define code to create a ubunutu container, update repository and install git.

FROM ubuntu
MAINTAINER logiclabs
RUN apt-get update
RUN apt-get install -y git

FROM ubuntu
MAINTAINER aziz
RUN apt-get update
RUN apt-get install -y git
RUN apt-get install tree

FROM ubuntu
MAINTAINER aziz
RUN apt-get update && apt-get install -y git tree

 

Scenario4:  for CICD environment we install JAVA, jenkins, Git and Maven for java based project, JAVA is mandatory for jenkins but git and maven is the requirement for the code.

 

Image Layers:Docker Images are the combination of layers, when you pull an image from docker hub a number of layers downloaded.

Docker Image Layer

Docker Registry: Registry is a location where docker images are saved.

  1. Public Registry : hub.docker.com
  2. Private Registry: it is paid version registry.

Create a customize image from container running ubuntu and install git, create an image from container and uploaded into public registry.

  1. #docker run --name myubuntu -it ubuntu
  2. #apt-get update
  3. #apt-get install git
  4. #exit

Convert container into an image.

  1. #docker commit myubuntu aziz27uk/starubuntu (image name should start with userID of docker hub, image name is aziz27uk/starubuntu)
  2. Image is available in docker host which need to upload into docker hub.
  3. Login to docker hub from terminal.
  4. #docker login (enter login name and password)
  5. #docker push aziz27uk/starubuntu
  6. login to docker hub and check your images in repositories.

Docker Container Orchestration (Docker Swarm):

docker swarm