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
       
       
       

 

 

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