Sunday, September 8, 2024

Docker Commands Cheat Sheet: From Basics to Advanced

Docker Commands Cheat Sheet: From Basics to Advanced






1. Docker Installation

  • Command: `docker --version`
  • Description: Check Docker installation and version.

Example: docker --version`  

Output: `Docker version 20.10.7, build f0df350`


2. Docker Images

List Docker Images

  •   Command: docker images
  •   Description: Lists all Docker images on your local machine.

  Example: docker images

   Output: Lists all images with columns: REPOSITORY, TAG, IMAGE ID, etc.


Pull a Docker Image

  •   Command: docker pull [image_name]
  •   Description: Downloads a Docker image from a registry (e.g., Docker Hub).

  Example: docker pull nginx

   Output: Downloads the latest nginx image.


Remove a Docker Image

  •   Command: docker rmi [image_id]
  •   Description: Removes a Docker image from your local machine.

  Example:docker rmi 7b28eabc0405 

   Output: Deletes the image with the specified ID.


Search for a Docker Repository

  • Command: docker search [repository_name]
  • Description: Searches Docker Hub for repositories that match the given name or keyword.

Example: docker search rizwanzafar/pyapp 

Output: Displays a list of public repositories related to "rizwanzafar/pyapp" if available on Docker Hub.


 3. Docker Containers

Run a Docker Container

  •   Command: docker run [image_name]
  •   Description: Creates and runs a new container from a specified image.

  Example: docker run nginx

  Output: Runs an nginx server in a container.


Run a Docker with name

  •   Command: docker run --name myContainer [image_name]
  •   Description: Creates and runs a new container from a specified image with name.

  Example: docker run --name reactapp rizwanzfar/reactapp

  Output: Runs an reactapp  server in a container name reactapp.


Run a Docker on port

  •   Command: docker run -p computerPort:containerPort [image_name]
  •   Description: Creates and runs a new container from a specified image on our computer port.
    I wrote 3000 bcoz I know react by default run on port 3000 in container

  Example: docker run -p 5000:3000 rizwanzfar/reactapp

  Output: Runs a reactapp server on our system at port 5000. 


List Running Containers

  •   Command: docker ps
  •   Description: Lists all currently running containers.

  Example: docker ps

   Output: Displays active containers with details like CONTAINER ID, IMAGE, etc.


List All Containers

  •   Command: docker ps -a
  •   Description: Lists all containers, including stopped ones.

  Example: docker ps -a  

   Output: Shows all containers with their statuses.


Stop a Running Container

  •   Command: docker stop [container_id]
  •   Description: Stops a running container.

  Example: docker stop d4c3d4c3d4c3

   Output: Stops the container with the given ID.


 Remove a Docker Container

  •   Command: docker rm [container_id]
  •   Description: Deletes a stopped container.

  Example: docker rm d4c3d4c3d4c3

   Output: Removes the container with the specified ID.


Start a Stopped Container

  •   Command: docker start [container_id]
  •   Description: Starts a container that has been stopped.

  Example: docker start d4c3d4c3d4c3 

   Output: Restarts the container.


 Run a Container in Detached Mode 

  •   Command: docker run -d [image_name]
  •   Description: Runs a container in the background (detached mode).

  Example: docker run -d nginx

    Output: Runs nginx in the background and outputs the container ID.


4. Docker Volumes

Create a Docker Volume

  •   Command: docker volume create [volume_name]
  •   Description: Creates a new Docker volume.

  Example: docker volume create my_volume 

    Output: Creates a volume named `my_volume


List Docker Volumes

  •   Command: docker volume ls
  •   Description: Lists all Docker volumes on your system.

  Example: docker volume ls

   Output: Lists all volumes with details.


Remove a Docker Volume

  •   Command: docker volume rm [volume_name]
  •   Description: Deletes a Docker volume.

  Example: docker volume rm my_volume

    Output: Deletes the volume my_volume


5. Docker Networking

List Docker Networks

  •   Command: docker network ls
  •   Description: Lists all Docker networks.

  Example: docker network ls

   Output: Lists all networks, e.g., bridge, host, etc.


Create a Docker Network

  •   Command: docker network create [network_name]
  •   Description: Creates a new custom Docker network.

  Example: docker network create my_network 

   Output: Creates a network named my_network


Connect a Container to a Network

  •   Command: docker network connect [network_name] [container_id]
  •   Description: Connects a running container to an existing network.

  Example: docker network connect my_network d4c3d4c3d4c3 

   Output: Connects the specified container to my_network


6. Docker Compose

Run Docker Compose

  •   Command: docker-compose up
  •   Description: Builds, (re)creates, starts, and attaches to containers for a service.

  Example: docker-compose up

  Output: Starts all services defined in the docker-compose.yml


Stop Docker Compose

  •  Command: docker-compose down
  •   Description:** Stops and removes all containers, networks, and volumes defined by the docker-compose.yml

  Example: docker-compose down

    Output: Stops and cleans up the Docker Compose environment.


Build and Run Containers in Detached Mode

  • Command: docker compose up -d --build
  • Description: Builds the images (if not already built) and starts the containers defined in a docker-compose.yml file in detached mode (in the background). The --build flag forces a rebuild of the images before starting the containers.

Example: docker compose up -d --build

Output: Rebuilds the Docker images (if necessary) and runs the containers in the background, allowing you to continue using your terminal.


7. Docker Advanced Commands

Inspect a Docker Container

  •   Command: docker inspect [container_id]
  •   Description: Displays detailed information about a container.

  Example: docker inspect d4c3d4c3d4c3

   Output: Shows JSON output with details of the container.


View Container Logs

  •   Command: docker logs [container_id]
  •   Description: Fetches and displays logs from a container.

  Example: docker logs d4c3d4c3d4c3 

   Output: Displays the container’s logs.


Run a Command in a Running Container

  Command: docker exec [container_id] [command]

  Description: Executes a command inside a running container.

  Example: docker exec d4c3d4c3d4c3 ls /var/logs

  Output: Lists logs inside the container.


Prune Unused Docker Resources

  •   Command: docker system prune
  •   Description: Removes all stopped containers, unused networks, and dangling images.

  Example: docker system prune

   Output: Frees up space by removing unused Docker resources.


Build and Push an Image to Docker Hub

  •   Command: docker build -t [repository_name]:[tag]. && docker push [repository_name]:[tag]
  •   Description: Builds an image from a Dockerfile and pushes it to Docker Hub

  Example: docker build -t myrepo/myimage:v1 . && docker push myrepo/myimage:v1 

  Output: Builds and uploads the image to your Docker Hub repository.


8. Docker Swarm (Orchestration)

Initialize Docker Swarm

  •   Command: docker swarm init
  •   Description: Initializes a new Docker Swarm cluster

  Example:docker swarm init 

   Output: Initializes the Swarm and displays the join token.


Deploy a Stack to Docker Swarm

  •   Command: docker stack deploy -c [stack_file] [stack_name]
  •   Description: Deploys a stack (collection of services) to Docker Swarm

  Example: docker stack deploy -c docker-stack.yml mystack 

   Output: Deploys the stack defined in docker-stack.yml


Update a Service in Docker Swarm

  •   Command: docker service update [service_name]
  •   Description: Updates the configuration of an existing service in the Swarm.

  Example: docker service update --replicas 5 myservice

   Output: Scales the service to 5 replicas




Conclusion

This cheat sheet covers the essential Docker commands you'll need from basic container management to advanced orchestration with Docker Swarm. Each command includes a brief description and an example, making it easy to follow along and apply to your Docker projects.


This format is SEO-friendly and optimized for readers looking for quick, actionable information on Docker commands.

Sunday, July 7, 2024

How to Install or Update the Qualys Cloud Agent on Red Hat Linux

 How to Install or Update the Qualys Cloud Agent on Red Hat Linux






Qualys Cloud Agent is a powerful tool for continuous monitoring and vulnerability management of your systems. This guide will walk you through the steps to install and update the Qualys Cloud Agent on a Red Hat Linux server.

Installation Steps

1. Download the Qualys Cloud Agent Package

First, download the Qualys Cloud Agent package for Linux from the official Qualys website.

2. Unzip the Downloaded Package

Unzip the downloaded package using the following command:
command: unzip QualysCloudAgent-Linux.zip

3. Install the Unzipped Package

Install the Qualys Cloud Agent package using the rpm command:
command: sudo rpm -ivh QualysCloudAgent.rpm

4. Activate the Agent

Activate the Qualys Cloud Agent with your specific Activation ID and Customer ID:
command: sudo /usr/local/qualys/cloud-agent/bin/qualys-cloud-agent.sh ActivationId=<ACTIVATION_ID> CustomerId=<CUSTOMER_ID>

5. Start the Agent Service

Start and enable the Qualys Cloud Agent service to run at boot:
commands:
sudo systemctl start qualys-cloud-agent
sudo systemctl enable qualys-cloud-agent

6. Check Logs (Optional)

Monitor the agent logs to ensure it is functioning correctly:
command: tail -f /var/log/qualys/qualys-cloud-agent.log

7. Check the Installed Version (Optional)

Verify the installed version of the Qualys Cloud Agent:
commands:
rpm -q qualys-cloud-agent 
or
sudo yum info qualys-cloud-agent


Updating the Qualys Cloud Agent

If an older version of the Qualys Cloud Agent is already installed, follow these steps to update to the latest version.

1. Remove Old version

Remove the existing Qualys Cloud Agent (optional, but recommended to ensure a clean installation)

commands:
sudo systemctl stop qualys-cloud-agent
sudo yum remove qualys-cloud-agent

2.Unzip the Updated Package

Unzip the updated package:
command: unzip QualysCloudAgent-Linux.zip

3. Update the Package

Update the Qualys Cloud Agent using the rpm or yum command:
commands:
 sudo rpm -Uvh QualysCloudAgent.rpm
or 
sudo yum update QualysCloudAgent.rpm

4. Restart the Agent Service

Restart the Qualys Cloud Agent service to apply the update
command: sudo systemctl restart qualys-cloud-agent

5. Verify the Updated Version

Check the updated version of the Qualys Cloud Agent:
commands
rpm -q qualys-cloud-agent
or
yum info qualys-cloud-agent


By following these steps, you can easily install and keep your Qualys Cloud Agent up to date on a Red Hat Linux server. This ensures continuous security monitoring and compliance for your systems.



Conclusion

Maintaining up-to-date security tools is crucial for protecting your systems. The Qualys Cloud Agent provides robust capabilities for vulnerability management and continuous monitoring. Follow the steps outlined in this guide to ensure your agent is properly installed and updated.

Ensure to replace <ACTIVATION_ID> and <CUSTOMER_ID> with your specific credentials. For more detailed information, refer to the official Qualys documentation.

Wednesday, July 3, 2024

Automating AEM Deployment with Jenkins

 Automating AEM Deployment with Jenkins






Automating the deployment process of Adobe Experience Manager (AEM) can significantly enhance your development workflow. In this blog post, we'll guide you through setting up a Jenkins pipeline for deploying AEM packages. This includes fetching code from BitBucket, building it with Maven, and deploying to AEM instances.

Prerequisites

Before starting, ensure you have the following:

  • Jenkins installed and configured.
  • Maven installed on your Jenkins server.
  • Credentials for your BitBucket repository.
  • AEM instances (Author, Publish, Dispatcher) up and running.


  • Jenkins Pipeline Script

    Here is a step-by-step Jenkins pipeline script for AEM deployment:

    Setting Up the Environment

    We define essential environment variables for AEM instances and user credentials.

    pipeline {
        agent any
        environment {
            AUTHOR_01 = "Author URL"
            PUBLISH_01 = "Publish URL"
            DISPATCHER_01 = "Dispatcher URL"
            PORT = "your port"
            PROTOCOL = "https/http"
            CONSOLE_USER = "username"
            CONSOLE_PASSWORD = "password"
        }
        tools {
            maven 'maven3'
        }

    Fetching Code from BitBucket

    In this stage, we clone the code from the specified branch in BitBucket.

        stages {
            stage('Get Code from BitBucket') {
                steps {
                    git branch: 'branch name', credentialsId: 'Credential ID', url: 'repo URL'
                }
            }


    Building the Project

    Next, we build the project using Maven. We use a Maven settings file to configure the build.

            stage('Build') {

                steps {

                    configFileProvider([configFile(fileId: '[file ID]', variable: 'MAVEN_SETTINGS')]) {

                        sh 'mvn -s $MAVEN_SETTINGS clean install'

                    }

            }

    }


    Deployment to AEM

    We deploy the built packages to both the Author and Publish instances in parallel.

            stage('Deployment') {

                parallel {

                    stage('Author') {

                        steps {

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.apps-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.apps/target/projectName.ui.apps-1.0-SNAPSHOT.zip ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.apps-1.0-SNAPSHOT.zip --insecure'


                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.config-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.config/target/projectName.ui.config-1.0-SNAPSHOT.zip ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.config-1.0-SNAPSHOT.zip --insecure'

                            

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=install -F name=projectName.core-1.0-SNAPSHOT.jar -F force=true -F bundlefile=@./core/target/projectName.core-1.0-SNAPSHOT.jar -F bundlestartlevel=20 ${PROTOCOL}://${AUTHOR_01}:${PORT}/system/console/bundles --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=start -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/system/console/bundles/projectName.core --insecure'


                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.content-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.content/target/projectName.ui.content-1.0-SNAPSHOT.zip ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.content-1.0-SNAPSHOT.zip --insecure'

                            

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.all-1.0-SNAPSHOT.zip -F force=true -F file=@./all/target/projectName.all-1.0-SNAPSHOT.zip ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.all-1.0-SNAPSHOT.zip --insecure'

                        }

                    }

                    stage('Publisher') {

                        steps {

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.apps-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.apps/target/projectName.ui.apps-1.0-SNAPSHOT.zip ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.apps-1.0-SNAPSHOT.zip --insecure'


                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.config-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.config/target/projectName.ui.config-1.0-SNAPSHOT.zip ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.config-1.0-SNAPSHOT.zip --insecure'

                            

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=install -F name=projectName.core-1.0-SNAPSHOT.jar -F force=true -F bundlefile=@./core/target/projectName.core-1.0-SNAPSHOT.jar -F bundlestartlevel=20 ${PROTOCOL}://${PUBLISH_01}:${PORT}/system/console/bundles --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=start -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/system/console/bundles/projectName.core --insecure'


                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.content-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.content/target/projectName.ui.content-1.0-SNAPSHOT.zip ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.content-1.0-SNAPSHOT.zip --insecure'

                            

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.all-1.0-SNAPSHOT.zip -F force=true -F file=@./all/target/projectName.all-1.0-SNAPSHOT.zip ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.all-1.0-SNAPSHOT.zip --insecure'

                        }

                    }

                }

            }

        }

        post {

            always {

                emailext to: "email address",

                subject: "<email title>",

                body: "<email body>"

            }

        }

    }

    All Script in Once

    pipeline {

        agent any

        environment {

            AUTHOR_01="Author URL"

            PUBLISH_01="Publish URL"

            DISPATCHER_01="Dispatcher URL"

            PORT="your port"

            PROTPOCOL="https/http"

            CONSOLE_USER="username"

            CONSOLE_PASSWORD="password"

            

        }

        tools {

            maven 'maven3' 

        }

        stages {

            stage('Get Code from BitBucket') {

                steps {

                    git branch: 'branch name', credentialsId: 'Credential ID', url: 'repo URL'

                }

            }

            

            stage('Build'){

                steps {

                    configFileProvider(

                        [configFile(fileId: '[file ID]', variable: 'MAVEN_SETTINGS')]) {

                            sh 'mvn -s $MAVEN_SETTINGS clean install'

                    }

                }

                

            }

            

            stage('Deployment') {

                    parallel {

                        stage('Author') {

                            steps {

                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.apps-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.apps/target/projectnName.ui.apps-1.0-SNAPSHOT.zip ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.apps-1.0-SNAPSHOT.zip --insecure'


                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.config-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.config/target/projectnName.ui.config-1.0-SNAPSHOT.zip  ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.config-1.0-SNAPSHOT.zip --insecure'

                                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=install -F name=projectnName.core-1.0-SNAPSHOT.jar -F force=true -F bundlefile=@./core/target/projectnName.core-1.0-SNAPSHOT.jar -F bundlestartlevel=20 ${PROTPOCOL}://${AUTHOR_01}:${PORT}/system/console/bundles --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=start -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/system/console/bundles/projectnName.core --insecure'


                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.content-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.content/target/projectnName.ui.content-1.0-SNAPSHOT.zip  ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.content-1.0-SNAPSHOT.zip --insecure'

                                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.all-1.0-SNAPSHOT.zip -F force=true -F file=@./all/target/projectnName.all-1.0-SNAPSHOT.zip ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.all-1.0-SNAPSHOT.zip --insecure'


                            }

                        }

                        stage('Publisher') {

                            steps {

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.apps-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.apps/target/projectnName.ui.apps-1.0-SNAPSHOT.zip ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.apps-1.0-SNAPSHOT.zip --insecure'


                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.config-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.config/target/projectnName.ui.config-1.0-SNAPSHOT.zip  ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.config-1.0-SNAPSHOT.zip --insecure'

                                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=install -F name=projectnName.core-1.0-SNAPSHOT.jar -F force=true -F bundlefile=@./core/target/projectnName.core-1.0-SNAPSHOT.jar -F bundlestartlevel=20 ${PROTPOCOL}://${PUBLISH_01}:${PORT}/system/console/bundles --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=start -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/system/console/bundles/projectnName.core --insecure'


                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.content-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.content/target/projectnName.ui.content-1.0-SNAPSHOT.zip  ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.content-1.0-SNAPSHOT.zip --insecure'

                                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.all-1.0-SNAPSHOT.zip -F force=true -F file=@./all/target/projectnName.all-1.0-SNAPSHOT.zip ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.all-1.0-SNAPSHOT.zip --insecure'


                            }

                        }

                        

                    }

                }

            

        }

        post{

            always{

                emailext to: "email address",

                subject: "<email title>",

                body: "<email body>"

           }

        }


    }

    Conclusion

    By automating the deployment of AEM packages using Jenkins, you can streamline your workflow, reduce manual errors, and ensure a consistent deployment process. This script covers essential stages such as fetching code, building the project, and deploying it to AEM instances.



    Thursday, June 27, 2024

    How to Set Up and Manage a Docker Swarm: A Comprehensive Guide

     Set Up and Manage a Docker Swarm






    Introduction

    Docker Swarm is a powerful container orchestration tool that allows you to manage a cluster of Docker nodes as a single virtual system. In this guide, we will walk you through the steps to set up and manage a Docker Swarm, including initializing the Swarm, adding worker and manager nodes, troubleshooting connection issues, creating and scaling services, and rolling out updates.

    Initializing Docker Swarm

    To start using Docker Swarm, you need to initialize it on your primary machine, which will act as the manager node. Run the following command to initialize Docker Swarm:

    command: docker swarm init --advertise-addr 192.168.67.9

    This command sets up your machine as the manager and advertises its IP address for other nodes to join the Swarm.



    Adding Worker Nodes

    Worker nodes perform tasks assigned by the manager node. To add a worker node to your Swarm, you need a join token. Obtain this token by executing the following command on the manager node:

    command: sudo docker swarm join-token worker

    You will receive a command with a token that looks similar to the following:

    command: docker swarm join --token SWMTKN-1-1cjqj7bvb19mgsi26mc4qfgmnrtturj959mb1ne9pu1im7a8vw-9hl3z4iwjgrucleh2vr986rrg 192.168.67.9:2377

    Run this command on the worker node to join it to the Swarm.


    Adding Manager Nodes (Optional)

    To add more manager nodes for high availability and fault tolerance, obtain a join token specifically for manager nodes by executing:

    command: sudo docker swarm join-token manager

    Use the provided token to join the additional manager nodes. 


    Troubleshooting Connection Issues

    If you encounter connection issues while adding a worker node, it might be due to firewall settings. On the manager node, run the following commands to open the necessary port:

    command:
    sudo firewall-cmd --add-port=2377/tcp --permanent sudo firewall-cmd --reload

    After adjusting the firewall settings, try adding the worker node again.




    Verifying Node Addition

    To verify that a worker node has been successfully added to the manager node, execute:
    command: sudo docker node ls
    This command lists all nodes in the Swarm along with their roles and status.


    Additionally, you can check the Swarm section in the Docker info output by running:
    command: sudo docker info
    If the node was added successfully, it will be listed in the Swarm section.




    Creating a Service

    Docker Swarm allows you to deploy services across the cluster. For example, if you have an image named nodeapp:crud_exit, you can create a service with three replicas running on port 4000 using the following command:

    command: docker service create --name nodeapp --replicas 3 -p 4000:4000 rizwanzafar/nodeapp:crud_exit

    This command instructs Docker Swarm to run three instances of the nodeapp service, each listening on port 4000.

    To see which nodes are running the replicas, use:

    command: docker service ps nodeapp





    Scaling the Service

    You might need to scale your services based on demand. To increase or decrease the number of replicas of a running service, run:

    command: docker service scale nodeapp=5

    This command scales the nodeapp service to five replicas.



    Rolling Out Updates

    Updating a service in Docker Swarm is straightforward. If you need to deploy a different image or a new tag of the same image, use the following command:

    command: docker service update --image rizwanzafar:01 nodeapp

    This command updates the nodeapp service to use the new image rizwanzafar:01.



    Node Availability (Optional)

    if you you want my new created service should not be doploy to this specfic node then you can
    dtrain the avilabilty of that node
    command : docker node update --availability drain node-id check node status : docker node ls

    and let now you want to revert back to availabel status you can run follwoing command
    command : docker node update --availability active node-id
    check node status : docker node ls

    Managing Node Roles in Docker Swarm

    Use following command to change a manager node to a worker node.

    • docker node demote <node_id>
    Use following command to change a worker node to a manager node.

    • docker node promote <node_id>

    Conclusion

    Setting up and managing a Docker Swarm is an efficient way to handle containerized applications at scale. By following this guide, you can initialize a Swarm, add worker and manager nodes, troubleshoot issues, create and scale services, and roll out updates with ease. Docker Swarm provides robust features for container orchestration, making it an essential tool for modern DevOps practices.

    Feel free to leave comments or questions below, and don't forget to share your experience with Docker Swarm!


    Wednesday, June 26, 2024

    How to Mount a Docker Container with a Volume on Different Servers

    How to Mount a Docker Container with a Volume on Different Servers





     Mounting a Docker container with a volume that resides on a different server involves setting up network connectivity and configuring network file systems like NFS. This guide will help you set up an NFS to share a Docker volume across different servers. let my volume be available on Redhat and the container is running on Ubuntu


    Step-by-Step Guide to Setting Up NFS


    1. Install NFS Server on Red Hat

    First, install and configure the NFS server on your Red Hat server:
    commands:
    sudo yum install nfs-utils
    sudo systemctl enable nfs-server 
    sudo systemctl start nfs-server

    2. Export the Docker Volume Directory

    Edit the NFS export configuration to share the Docker volume directory:
    command:
    sudo vi /etc/exports
    add the docker volume path with the IP of the server that will access this (Ubuntu)
    example : 
    /var/lib/docker/volumes/testData/_data ip_of_ubuntu(rw,sync,no_subtree_check)



    3. Restart NFS Service

    Restart the NFS service to apply the changes:
    command: sudo systemctl restart nfs-server

    Mounting the NFS Volume on Ubuntu


    4. Install NFS Client on Ubuntu

    Install the NFS client utilities on your Ubuntu server:
    commands:
    sudo apt-get update 
    sudo apt-get install nfs-common

    5. Mount the NFS Share on Ubuntu

    Create a mount point and mount the NFS share:
    commands: 
    sudo mkdir -p /mnt/tetData  #this is the place on ubunte where volume will be mount
    sudo mount -t nfs 192.168.67.9:/var/lib/docker/volumes/tetData/_data /mnt/tetData
    Replace 192.168.67.9 with the IP address of your Red Hat server.

    Using the NFS Volume in Docker

    6. Update Docker Compose Configuration

    Modify your docker-compose.yml to use the NFS-mounted directory:
    compose file syntax


    Additional Considerations

    • NFS Security: Secure your NFS configuration based on your network and security requirements.
    • Persistent Mount: To make the NFS mount persistent across reboots, add an entry to /etc/fstab on your Ubuntu server.
    • command:  echo '192.168.67.9:/var/lib/docker/volumes/tetData/_data /mnt/tetData nfs defaults 0 0' | sudo tee -a /etc/fstab

    Permission Issues

    1. Verify and Adjust Permissions on the Red Hat Server:
       

       Ensure that the directory and its contents on the Red Hat server have the appropriate permissions. You need to set the ownership and permissions so that the Docker container running on Ubuntu can access it.


     commands:  

       sudo chown -R 999:999 /var/lib/docker/volumes/tetData/_data

       sudo chmod -R 755 /var/lib/docker/volumes/tetData/_data


     Here, `999:999` corresponds to the `mongodb` user and group ID used by the official MongoDB Docker image.

    2. Check and Adjust Local Directory Permissions on Ubuntu


       Ensure the local mount point directory on Ubuntu has the correct permissions:


       commands

       sudo chown -R 999:999 /mnt/tetData

       sudo chmod -R 755 /mnt/tetData


    3. Restart Services:


    Restart the NFS server on the Red Hat machine to apply changes:

    commands: 

    sudo systemctl restart nfs-server

       


    By following these steps, you can mount a Docker container on one server to a volume residing on another server, leveraging the NFS for seamless data sharing. Adjust configurations and permissions according to your specific setup and requirements.




    Sunday, June 23, 2024

    How to Install Docker on Ubuntu 22.04 (Jammy Jellyfish)

     How to Install Docker on Ubuntu 22.04
    (Jammy Jellyfish)











    Installing Docker on Ubuntu 22.04 is a straightforward process. Follow these steps to get Docker up and running on your system:

    Step-by-Step Guide to Install Docker on Ubuntu 22.04

    1. Update the Package List

      First, ensure your package list is up to date:
      command: sudo apt update

    2. Install Required Packages

      Install the necessary packages for Docker installation:
      command: sudo apt install apt-transport-https ca-certificates curl software-properties-common

    3. Add the Docker GPG Key

      Add Docker’s official GPG key to your system:
      command: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

    4. Add the Docker Repository

      Set up the Docker repository:
      command: echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

    5. Update the Package List Again

      Refresh your package list to include Docker’s repository:
      command: sudo apt update

    6. Install Docker

      Install Docker CE (Community Edition):
      command: sudo apt install docker-ce

    7. Verify Docker Installation

               Check that Docker is installed and running:
               command: sudo systemctl status docker


    By following these steps, you will successfully install Docker on your Ubuntu 22.04 system, allowing you to start leveraging Docker containers for your projects.

    For more detailed guides and troubleshooting, refer to the official Docker documentation.


    How to install Docker in Redhat






    Saturday, June 15, 2024

     Deploying Your First Docker Image Using Kubernetes: A Step-by-Step Guide

     Deploying Your First Docker Image Using Kubernetes: A Step-by-Step Guide










    Deploying a Docker image via Kubernetes can seem daunting at first, but with this comprehensive guide, you'll be able to deploy your first Docker image with ease. Follow these steps to get your application up and running using Kubernetes and Minikube.

    Prerequisites

    Before starting, make sure you have kubectl and Minikube installed on your local machine. Verify the installations by executing the following commands:

    • command: kubectl version --client 
    • command: minikube status
    If you have not already installed Minikube and kubectl, or if you encounter errors, refer to our installation guide: Introduction to Kubernetes and Minikube Installation.



    Step-by-Step Guide to Deploying via Kubernetes

    1. Create a Deployment

    First, you need to create a deployment. Use the following command, replacing deploymentName with your desired deployment name and imageName with your Docker image name:

    command: kubectl create deployment deploymentName --image=imageName


    2. Verify the Deployment

    To ensure that your deployment and pods are running, execute:

    • command: kubectl get deployments
    • command: kubectl get pods




    3. Bind the Port

    Next, bind the port. Assuming your Docker image exposes port 3000 internally, you can expose this port externally using the following command

    command:kubectl expose deployment deploymentName --type=LoadBalancer --port=3000


    4. Notify Minikube

    Finally, inform Minikube about the service. This will provide you with a URL to access your application. Run:
    command: minikube service deploymentName



    Copy the provided URL and paste it into your browser to see your application in action.


    Copy the provided URL and paste it into your browser to see your application in action.


    Rolling Out Updates

    Once your application is deployed, you might need to update it. Rolling out updates in Kubernetes is straightforward. Use the following command to update your deployment with a new image version:


    command: kubectl set image deployment deploymentName containerName=newImageName:newTag

    Verify the rollout status with the command: kubectl rollout status deployment deploymentName



    now  you can see on the same service/url my updated image is running



    Rolling Back Updates

    If something goes wrong with your update, you can easily roll back to the previous version. Use the following command to roll back the deployment:

    command:kubectl rollout undo deployment/deploymentName


    after running the rollout undo command hit your Project URL again you will see your project is rolled back to the previous version




    Conclusion

    By following these steps, you can easily deploy your first Docker image using Kubernetes and Minikube. This guide helps streamline the process, ensuring a successful deployment. With these foundational skills, you can explore more advanced features of Kubernetes and enhance your containerized applications further.

    For more detailed information on Kubernetes and Docker, check out our other blog posts and tutorials. Happy deploying!