Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions Docker inside Docker/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Docker Inside Docker (DinD) Guide πŸš€

## Overview

This guide explains how to set up Docker inside Docker (DinD). This approach is useful for CI/CD pipelines, enabling Docker commands to be executed within a Docker container.

## Prerequisites πŸ“‹

- Docker installed on the host machine
- Basic knowledge of Docker commands
- Docker Compose (optional, for easier orchestration)

## Step-by-Step Guide πŸ› οΈ

### Step 1: Install Docker 🐳

If Docker is not already installed on your host machine, follow these steps:

1. **Update the package database:**

```sh
sudo apt-get update

2. **Install prerequisites:**
```sh
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

3. **Add Docker’s official GPG key:**
```sh
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -


4. **Add Docker’s repository:**
```sh
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"


5. **Install Docker CE:**
```sh
sudo apt-get update
sudo apt-get install docker-ce


6. **Verify Docker installation:**
```sh
docker --version


### Step 2: Create a Dockerfile for DinD πŸ“„
**Create a Dockerfile that uses the official Docker-in-Docker image:**
```dockerfile
# Dockerfile
FROM docker:20.10.7-dind

# Optional: Install any additional packages
RUN apk add --no-cache git

# Optional: Create a working directory
WORKDIR /app

# Optional: Copy application files
COPY . /app

# Entry point for the Docker container
CMD ["sh"]
```

### Step 3: Build the Docker Image πŸ—οΈ
**Build the Docker image from the Dockerfile:**
```sh
docker build -t my-dind-image .
```

### Step 4: Run the DinD Container ▢️
**Run a container using the DinD image with necessary Docker daemon options:**
```sh
docker run --privileged --name my-dind-container -d docker:20.10.7-dind
```
**--privileged grants the container extended privileges.**
**--name assigns a name to the container.**
**-d runs the container in detached mode.**


### Step 5: Interact with Docker Inside the Container πŸ™
1. **Access the running DinD container:**
```sh
docker exec -it my-dind-container sh

2. **Verify Docker daemon is running inside the container:**
```sh
docker info

3. **Run Docker commands inside the container:**
```sh
docker run hello-world

### Step 6: Clean Up 🧹
**To stop and remove the DinD container:**
```sh
docker stop my-dind-container
docker rm my-dind-container
```
**To remove the Docker image:**
```sh
docker rmi my-dind-image
```
### Conclusion πŸŽ‰
You have successfully set up Docker inside Docker (DinD). This configuration is ideal for CI/CD pipelines and allows you to run Docker commands within a Docker container.


143 changes: 143 additions & 0 deletions Setting up Ci/CD pipeline using jenkins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Jenkins CI/CD Setup Guide

Whether you're new to Jenkins or looking to set up a CI/CD pipeline on your server, this comprehensive guide will help you through clear, step-by-step instructions.

## Pre-requisites

- Ubuntu OS (Xenial or later)
- sudo privileges
- Internet access
- t2.medium instance type or higher

---

# Execute all the command step by step

## Install Jenkins

1. **Update your system**:

```bash
sudo apt update
sudo apt upgrade -y

2. **Install Java**:
```bash
sudo apt install openjdk-11-jdk -y

3. **Add Jenkins repository**:
```bash
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null

4. **Install Jenkins**:
```bash
sudo apt update
sudo apt install jenkins -y

5. **Start Jenkins service**:
```bash
sudo systemctl start jenkins
sudo systemctl enable jenkins

6. **Access Jenkins**:
>Open a web browser and go to http://<your-server-ip>:8080.
>Unlock Jenkins by copying the password from the initialAdminPassword file:
```bash
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

# Configure Jenkins

- **Install suggested plugins** during the initial setup.
- **Create an Admin User**:
- Follow the on-screen instructions to create your admin user.
- **Configure Jenkins URL**:
- Set the Jenkins URL to your server's IP address or domain name.

# Set Up a Jenkins Job

## Create a New Job:

1. Go to Jenkins Dashboard.
2. Click on `New Item`.
3. Enter a name for your job and select `Pipeline`. Click `OK`.

## Configure the Pipeline:

1. In the job configuration page, scroll down to the `Pipeline` section.
2. Select `Pipeline script from SCM`.
3. Choose `Git` and enter your repository URL.
4. Specify the branch to build (e.g., `main`).

# Create a Jenkinsfile

Create a `Jenkinsfile` in the root of your repository with the following content:

```groovy
pipeline {
agent any

stages {
stage('Build') {
steps {
echo 'Building...'
// Add build steps here
}
}
stage('Test') {
steps {
echo 'Testing...'
// Add test steps here
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
// Add deploy steps here
}
}
}

post {
always {
echo 'Cleaning up...'
// Add cleanup steps here
}
}
}

```
# Run the Pipeline

## Trigger the Pipeline:
- Go to your job in Jenkins.
- Click `Build Now` to trigger the pipeline.

## Monitor the Build:
- Click on the build number to see the build details.
- Check the console output for logs and debug information.

# Troubleshooting

## Common Issues

- **Jenkins not starting**: Check Jenkins logs for errors:
```bash
sudo journalctl -u jenkins


***Using all these processes, you will successfully set up a CI/CD pipeline using Jenkins. Now you can enjoy automating your build, test, and deployment processes, and if you are facing any issues, please don't hesitate to ask me. You can connect with me on:***

- [LinkedIn](https://www.linkedin.com/in/v-litesh-kumar-2094b5218)
- [Mail Me](mailto:kvlitesh@gmail.com)

Let's dive into Jenkins together and streamline your software delivery!

**Happy CI/CD-ing!** πŸš€