Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

Wednesday, July 15, 2020

Docker Commands - Mitun Technologies - 9980923226

Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com

                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/ 
Docker Commands

docker info: It will give status of weather docker is running or not  and also It will display the detailed information about docker engine. 

docker version: Show the Docker version information.

docker images (OR) docker image ls : List all images that are locally stored with the Docker engine.

docker run <<Docker Image>> : It will run the docker image.

Example: docker run hello-world: This command will download the hello-world image, if it is not already present, and run the hello-world as a container.

docker images <<Image Name>>: It will display the information about image.

docker images -q: It will display only the images IDs.

docker rmi << Image ID/Image Name>> (OR) docker image rm << Image ID/Image Name>>: It will delete an image from the local image store.
Example: docker rmi nginx

docker rmi $(docker images -q) (OR) docker rmi -f $(docker images -q) : It will remove all the images from docker engine.

docker run --name “hello-world-container” helloworld: Start the hello-world image with “hello- world-container” container name. 

docker create “hello-world-cont” helloworld : It will create a container called “hello-world-cont” from the image hello-world and it won’t start the container.

docker ps (OR) docker container ls: Lists running containers
(It will not display the stopped containers)

docker ps –a (OR) docker container ls --all (OR) docker container -a: Lists all containers (It will display the stopped containers along with running containers.)
                                                    
docker start <Container name|id>: It will start the container.

docker start webserver: It will start the webserver.

docker stop <container name|id> (OR) docker container stop <container name|id>: It will stop the docker container.

docker stop webserver: It will stop the container called webserver.

docker pause CID/CNAME: It will pause the container.

docker unpause CID/CNAME: It will unpause the container.

Docker Container status are, created, restarting, running, removing, paused, exited, or dead

docker ps -a --filter "name=mithun16thjune": It will display all the containers with name mithun16thjune name.

docker ps -a --filter 'exited=0' :

docker ps --filter status=running: It will display the all the running state containers.

docker ps --filter status=paused: It will display the all the paused state containers.

docker logs <container name>: It will display the logs for that container.

docker logs --tail 100 <<Container Name>>: Print the last 100 lines of a container’s logs.

docker top <<Container ID>>: This will shows the top processes in within in a container.

docker reanme <<Container Old Name>> <<Container New Name>>: It will rename the conatiner.

docker rm -f <<Container Name>>: It will remove the container.

docker rm -f webserver: It will stop and remove the running container with a single command.

docker stop $(docker ps -a -q): It will stop all the containers.

docker rm -f $(docker ps -aq): Delete all running and stopped containers.

docker kill <<CID/C Name>>: It will kill the container.

docker container prune: It will delete all stopped containers.

docker search <<Image Name>>: It will search all of the publicly available images on Docker
Hub(https://hub.docker.com).

docker pull <<Image Name>: Pull an image from Docker Hub

docker inspect <<CID>> : It will give information for container.

docker attach <<CID>> : It will connect to running container.

docker exec <<CID>> : Run a linux command in a running container.

docker stats <<CID>> : It will display a live stream of container resource usage statics.

docker network ls: List the networks.

docker network create mithuntechnologies : It will create the network with name called as mithuntechnologies.

docker network inspect bridge: Display detailed information on one or more networks.

docker network connect: Connect a container to a network.

docker network prune: Remove all unused networks.

docker run -it -v /Users/mithunreddyl/Desktop/dockervolumes:/mithuntechnoVol1 ubuntu : Create a container with volume mithuntechnoVol1.


docker run -it -v /Users/mithunreddyl/Desktop/dockervolumes:/mithuntechnoVol1:ro --name ubuntucontainer16 ubuntu : Create the Read only Volume.


docker run -it --volumes-from ubuntucontainer16 --name ubuntucontainer1604 ubuntu:16.04:
Create a container ubuntucontainer1604 that uses the same volumes as ubuntucontainer16

Can I mount same volume to multiple docker containers?
Ans) Yes you can add same location as a volume to many docker containers.

docker login: To sign into the Docker Hub.

docker logout: To logout from the Docker Hub. If no server is specified, then the default is used.


Thursday, January 16, 2020

Install Docker in Linux Server - Mithun Technologies - 9980923226

Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com
                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/
 
In Ubuntu Server
----------------------
Method-1
=======

Step 1: Update all Software Repositories using below command.

#sudo apt-get update

Step 2: Install a Docker using below command

#sudo apt install docker.io -y

Step 3: Enable and start the docker service as follows.

#sudo systemctl enable docker
#sudo systemctl start docker

Step 4: Check the  docker version

#docker --version

# You will get permison denied error as regular user dosn't have permisions to execute docker commands, add ubuntu user to docker group.

#sudo usermod -aG docker $USER
     or 
#sudo usermod -aG docker ubuntu

# Exit From Current SSH Terminal & SSH(Login) again .Then execute
docker ps

To Un Install a docker
-----------------------------

Use below command to un-install docker
#apt-get remove docker docker-engine docker.io -y
----------------------------------------------------------------------------------------------------------------------------
Method -2
========
Step 1: Update all Software Repositories using below command.
#apt-get update


Step 2: Install Docker using below command
#curl -fsSL get.docker.com | /bin/bash


Step 3: Check all the versions.
#apt-cache madison docker-ce


Step 4: If we want to install the specific version use the below command.
apt-get install docker-ce=<VERSION>

Step 5: If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

#usermod -aG docker  <<YourUser>>
============================================================================

 In Amazon Linux
-----------------------

sudo yum update -y       
sudo yum install docker -y
sudo service docker start

Add Regural user to dockergroup
sudo usermod -aG docker  <username>

ex:
sudo usermod -aG docker ec2-user

Once you add user to group exit from the server and login again.
# Get docker information
docker info

#Install Docker in Linux (Works for most of linux flavors).
sudo curl -fsSL get.docker.com | /bin/bash

Docker Home Directory/Working Dir:
/var/lib/docker

============================================================================
Install Docker on AWS RHEL  (Offcially No Support)
----------------------------------------------------------------------

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install docker-ce-3:18.09.1-3.el7 -y
sudo systemctl enable docker
sudo systemctl start docker

sudo docker info

# Check docker is installed or not
docker info

# You will get permison denied error as regular user dosn't have permisions to execute docker commands, add user to docker group.

sudo usermod -aG docker $USER
or
sudo usermod -aG docker ec2-user

# Exit From Current SSH Terminal & SSH(Login) again .Then execute
docker ps




Sunday, January 5, 2020

Jenkins Docker Swarm Integration - Mithun Technologies - 9980923226

Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com
                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/ 





Jenkins Docker Swarm Integration
=========================

1) CI/CD Pipeline Scrit to build and deploy single service in docker swarm


2) CI/CD Pipeline Scrit to build and deploy multiple services using docker stack(Compose File) in docker swarm


Pre Requisite:
==========

1) Docker Swarm Cluster
  
   https://www.youtube.com/watch?v=cuNW5Qwd-D4
  
2)  Setup CI/CD (Jenkins) Server   

=========Install Java, Jenkins, Docker in Ubuntu==============

sudo apt update -y

sudo apt install openjdk-8-jdk -y

wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update -y
sudo apt-get install jenkins -y

sudo systemctl status jenkins

sudo curl -fsSL get.docker.com | /bin/bash

# Add jenkins user to docker group
sudo usermod -aG docker jenkins
# Restart jenkins to reflect docker permisions
sudo systemctl restart jenkins

# Use below commands if you want to switch to jenkins user.
sudo -i -u jenkins
sudo su -s /bin/bash jenkins

##Plugins Used
sshAgent

Monday, November 18, 2019

Kubernetes Setup Using Kubeadm In AWS EC2 Ubuntu Servers - Mithun Technologies - +91-9980923226

Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com
                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/ 

Agenda: Kubernetes Setup Using Kubeadm In AWS EC2 Ubuntu Servers
=======================================================


Prerequisite:
==========


3 - Ubuntu Serves

1 - Manager  (4GB RAM , 2 Core) t2.medium

2 - Workers  (1 GB, 1 Core)     t2.micro


Note: Open Required Ports In AWS Security Groups. For now we will open All trafic.

==========COMMON FOR MASTER & SLAVES START ====

# First, login as ‘root’ user because the following set of commands need to be executed with ‘sudo’ permissions.

sudo su -

# Install Required packages and apt keys.

apt-get update -y
apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update -y



#Turn Off Swap Space

swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

# Install And Enable Docker

apt install docker.io -y
usermod -aG docker ubuntu
systemctl restart docker
systemctl enable docker.service


#Install kubeadm, Kubelet And Kubectl

apt-get install -y kubelet kubeadm kubectl kubernetes-cni

# Enable and start kubelet service

systemctl daemon-reload
systemctl start kubelet
systemctl enable kubelet.service

==========COMMON FOR MASTER & SLAVES END=====



===========In Master Node Start====================
# Steps Only For Kubernetes Master

# Switch to the root user.

sudo su -

# Initialize Kubernates master by executing below commond.

kubeadm init

#exit root user & exeucte as normal user

exit

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config


# To verify, if kubectl is working or not, run the following command.

kubectl get pods -o wide --all-namespaces

#You will notice from the previous command, that all the pods are running except one: ‘kube-dns’. For resolving this we will install a # pod network. To install the weave pod network, run the following command:

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

kubectl get nodes

kubectl get pods --all-namespaces


# Get token

kubeadm token create --print-join-command

=========In Master Node End====================


Add Worker Machines to Kubernates Master
=========================================

Copy kubeadm join token from and execute in Worker Nodes to join to cluster



kubectl commonds has to be executed in master machine.

Check Nodes
=============

kubectl get nodes


Deploy Sample Application
==========================

kubectl run nginx-demo --image=nginx --port=80

kubectl expose deployment nginx-demo --port=80 --type=NodePort


Get Node Port details
=====================
kubectl get services

Tuesday, October 22, 2019

Configuration of NFS Server - Mithun Technologies - +91-9980923226

   Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com
                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/

                                                          Configuration of NFS Server

Step 1: Install NFS Kernel Server
Before installing the NFS Kernel server, we need to update our system’s repository index with that of the Internet through the following apt command as sudo:

$ sudo apt-get update

The above command lets us install the latest available version of a software through the Ubuntu repositories.

Now, run the following command in order to install the NFS Kernel Server on your system:

$ sudo apt install nfs-kernel-server


Step 2: Create the Export Directory

sudo mkdir -p /mnt/share/

# As we want all clients to access the directory, we will remove restrictive permissions.
sudo chown nobody:nogroup /mnt/share/
sudo chmod 777 /mnt/share/

Step 3: Assign server access to client(s) through NFS export file

sudo vi /etc/exports


#/mnt/share/ <clientIP or Clients CIDR>(rw,sync,no_subtree_check,no_root_squash)
 #Ex:
/mnt/share/ *(rw,sync,no_subtree_check,no_root_squash)


Step 4: Export the shared directory

$ sudo exportfs -a


sudo systemctl restart nfs-kernel-server

Step 5: Open firewall for the client (s) PORT 2049


Configuring the Client Machine


Step 1: Install NFS Common
Before installing the NFS Common application, we need to update our system’s repository index with that of the Internet through the following apt command as sudo:

$ sudo apt-get update


$ sudo apt-get install nfs-common


# Test if we can mount nfs path with client systems folder.

Step 2: Create a mount point for the NFS host’s shared folder

sudo mkdir -p /mnt/sharedfolder_client

Step 3: Mount the shared directory on the client

sudo mount serverIP:/mnt/share/ /mnt/mountfolder_client

Thursday, October 3, 2019

Docker Swarm Setup - Mithun technologies +91-9980923226


             Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com
                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/ 

                                                        Docker Swarm Setup
                                                       ================

Rerequisites:
============

3 - Ubuntu Servers
     1 - Master
    2 - Workers
   
Steps:
======
         
1) Install Docker Community Edition in all the 3 Servers.
   And add user(ubuntu) to docker group.
                
   # Below command works for most of the Linux flavors except Redhat Linux
   sudo curl -fsSL get.docker.com | /bin/bash
  
   # Add Current User to docker group.
   sudo usermod -aG docker ${USER}
  
2) Open below ports in AWS Security Groups.
      
    TCP port 2377 for cluster management communications
    TCP and UDP port 7946 for communication among nodes
    UDP port 4789 for overlay network traffic.
   
    If you are planning on creating an overlay network with encryption     (--opt encrypted), you will  also need     to ensure ip protocol 50 (ESP) traffic is allowed.
     
3) Execute below command to initiate docker swarm manager in one system.
  
   # Initialize docker swarm cluster.
   docker swarm init
  
   # Get worker token
   docker swarm join-token worker
  
   # Get manager token to add another node as secondary manager
   docker swarm join-token manager
  
4) Add workers machines to cluster.
   #Execute join token(worker token from manager) in all worker machines.
  
  
5) Display docker cluster nodes in manager machine.

   docker node ls
  
6) Deploy Sample Docker Application in docker swarm cluster.

    docker service create --name webserver --replicas 2 -p 80:80 httpd     
  

Monday, September 16, 2019

PUSH/PULL Docker Image form Private Repository (Nexus) - Mithun Technologies +91-9980923226

PUSH/PULL Docker Image form Private Repository (Nexus)


Pre-Requisities:
Server 1: Ubuntu                                         Server 2: Ubuntu
Install the below softwares in Server1          Install the below softwares in Server2
Java 8                                                              Docker

Docker

Jenkins

Maven/Gradle
Server 1:
1   We are going to build our project using maven/gradle
2   Through docker file we are going to create an docker image for that project
  We are going to push the docker image to Nexus (docker hosted) repo
Server 2:
We are going to pull the docker image form Nexus (docker hosted) repo
2   Create a container using the docker image
Nexus Repository (docker hosted,proxy) Creation:
docker hosted:   
1) Login to your Nexus repository.
2) Create docker hosted


 Here give a name to the repo (dock-hosted), then we are going to assign a port to this docker hosted repo. Through this port we are going to access this repo. (Note: you should not give 8081 because it is already assigned to Nexus Repo, so use different port number)

In this case I have assigned 8083 for this repo.

3) Keep the remaining settings as it is and create repository




 Note: Open 8083 in AWS Security Groups.
Ubuntu Configuration : Server 1 & 2
Do these steps in both the servers in order to push and pull docker images from Nexus Repo.
1.     Login as root user
2.     Go to /etc/docker
            cd /etc/docker
3.     Then create a file called daemon.json
vi /etc/docker/daemon.json
4.     Write these script in daemon.json

{
  "insecure-registries": [ "13.234.21.143:8083" ]
}

(Here we are allowing our docker daemon to access the Nexus Hosted Repo)
5.     Save the file
6.     Restart docker service using below command.
            systemctl restart docker

 
Server 1: Login,Build & Push
1 Login to Nexus repo
docker login –u admin –p password 13.234.21.143:8083
(or)
docker login 13.234.21.143:8083



Build an image using below command.
docker build –t 13.234.21.143:8083/image1 .
           
(here while building an docker image we will use ip address with port for the docked hosted repo instead of username in hub.docker.com)


 
3 Push docker image to Nexus Repo



Server 2: Pull image/Run container
1.     Login to Nexus

2   Pull docker image

 
Build a container
docker run –d –p 8090:8080 –p 9990:9990 - -name wildfly 13.234.21.143:8083/image1
(I am using wildfly to deploy)     

   








    

 

Ansible Installation in Amazon Linux - Mithun Technologies - 9980923226

  Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com                                                 ...