Skip to content

Commit deea347

Browse files
authored
Merge pull request #396 from litesh1123/Docker Inside Docker (DIND)
Docker Inside Docker
2 parents 4652d07 + a1549df commit deea347

2 files changed

Lines changed: 253 additions & 0 deletions

File tree

Docker inside Docker/Readme.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Docker Inside Docker (DinD) Guide 🚀
2+
3+
## Overview
4+
5+
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.
6+
7+
## Prerequisites 📋
8+
9+
- Docker installed on the host machine
10+
- Basic knowledge of Docker commands
11+
- Docker Compose (optional, for easier orchestration)
12+
13+
## Step-by-Step Guide 🛠️
14+
15+
### Step 1: Install Docker 🐳
16+
17+
If Docker is not already installed on your host machine, follow these steps:
18+
19+
1. **Update the package database:**
20+
21+
```sh
22+
sudo apt-get update
23+
24+
2. **Install prerequisites:**
25+
```sh
26+
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
27+
28+
3. **Add Docker’s official GPG key:**
29+
```sh
30+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
31+
32+
33+
4. **Add Docker’s repository:**
34+
```sh
35+
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
36+
37+
38+
5. **Install Docker CE:**
39+
```sh
40+
sudo apt-get update
41+
sudo apt-get install docker-ce
42+
43+
44+
6. **Verify Docker installation:**
45+
```sh
46+
docker --version
47+
48+
49+
### Step 2: Create a Dockerfile for DinD 📄
50+
**Create a Dockerfile that uses the official Docker-in-Docker image:**
51+
```dockerfile
52+
# Dockerfile
53+
FROM docker:20.10.7-dind
54+
55+
# Optional: Install any additional packages
56+
RUN apk add --no-cache git
57+
58+
# Optional: Create a working directory
59+
WORKDIR /app
60+
61+
# Optional: Copy application files
62+
COPY . /app
63+
64+
# Entry point for the Docker container
65+
CMD ["sh"]
66+
```
67+
68+
### Step 3: Build the Docker Image 🏗️
69+
**Build the Docker image from the Dockerfile:**
70+
```sh
71+
docker build -t my-dind-image .
72+
```
73+
74+
### Step 4: Run the DinD Container ▶️
75+
**Run a container using the DinD image with necessary Docker daemon options:**
76+
```sh
77+
docker run --privileged --name my-dind-container -d docker:20.10.7-dind
78+
```
79+
**--privileged grants the container extended privileges.**
80+
**--name assigns a name to the container.**
81+
**-d runs the container in detached mode.**
82+
83+
84+
### Step 5: Interact with Docker Inside the Container 🐙
85+
1. **Access the running DinD container:**
86+
```sh
87+
docker exec -it my-dind-container sh
88+
89+
2. **Verify Docker daemon is running inside the container:**
90+
```sh
91+
docker info
92+
93+
3. **Run Docker commands inside the container:**
94+
```sh
95+
docker run hello-world
96+
97+
### Step 6: Clean Up 🧹
98+
**To stop and remove the DinD container:**
99+
```sh
100+
docker stop my-dind-container
101+
docker rm my-dind-container
102+
```
103+
**To remove the Docker image:**
104+
```sh
105+
docker rmi my-dind-image
106+
```
107+
### Conclusion 🎉
108+
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.
109+
110+
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Jenkins CI/CD Setup Guide
2+
3+
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.
4+
5+
## Pre-requisites
6+
7+
- Ubuntu OS (Xenial or later)
8+
- sudo privileges
9+
- Internet access
10+
- t2.medium instance type or higher
11+
12+
---
13+
14+
# Execute all the command step by step
15+
16+
## Install Jenkins
17+
18+
1. **Update your system**:
19+
20+
```bash
21+
sudo apt update
22+
sudo apt upgrade -y
23+
24+
2. **Install Java**:
25+
```bash
26+
sudo apt install openjdk-11-jdk -y
27+
28+
3. **Add Jenkins repository**:
29+
```bash
30+
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee \
31+
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
32+
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
33+
https://pkg.jenkins.io/debian binary/ | sudo tee \
34+
/etc/apt/sources.list.d/jenkins.list > /dev/null
35+
36+
4. **Install Jenkins**:
37+
```bash
38+
sudo apt update
39+
sudo apt install jenkins -y
40+
41+
5. **Start Jenkins service**:
42+
```bash
43+
sudo systemctl start jenkins
44+
sudo systemctl enable jenkins
45+
46+
6. **Access Jenkins**:
47+
>Open a web browser and go to http://<your-server-ip>:8080.
48+
>Unlock Jenkins by copying the password from the initialAdminPassword file:
49+
```bash
50+
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
51+
52+
# Configure Jenkins
53+
54+
- **Install suggested plugins** during the initial setup.
55+
- **Create an Admin User**:
56+
- Follow the on-screen instructions to create your admin user.
57+
- **Configure Jenkins URL**:
58+
- Set the Jenkins URL to your server's IP address or domain name.
59+
60+
# Set Up a Jenkins Job
61+
62+
## Create a New Job:
63+
64+
1. Go to Jenkins Dashboard.
65+
2. Click on `New Item`.
66+
3. Enter a name for your job and select `Pipeline`. Click `OK`.
67+
68+
## Configure the Pipeline:
69+
70+
1. In the job configuration page, scroll down to the `Pipeline` section.
71+
2. Select `Pipeline script from SCM`.
72+
3. Choose `Git` and enter your repository URL.
73+
4. Specify the branch to build (e.g., `main`).
74+
75+
# Create a Jenkinsfile
76+
77+
Create a `Jenkinsfile` in the root of your repository with the following content:
78+
79+
```groovy
80+
pipeline {
81+
agent any
82+
83+
stages {
84+
stage('Build') {
85+
steps {
86+
echo 'Building...'
87+
// Add build steps here
88+
}
89+
}
90+
stage('Test') {
91+
steps {
92+
echo 'Testing...'
93+
// Add test steps here
94+
}
95+
}
96+
stage('Deploy') {
97+
steps {
98+
echo 'Deploying...'
99+
// Add deploy steps here
100+
}
101+
}
102+
}
103+
104+
post {
105+
always {
106+
echo 'Cleaning up...'
107+
// Add cleanup steps here
108+
}
109+
}
110+
}
111+
112+
```
113+
# Run the Pipeline
114+
115+
## Trigger the Pipeline:
116+
- Go to your job in Jenkins.
117+
- Click `Build Now` to trigger the pipeline.
118+
119+
## Monitor the Build:
120+
- Click on the build number to see the build details.
121+
- Check the console output for logs and debug information.
122+
123+
# Troubleshooting
124+
125+
## Common Issues
126+
127+
- **Jenkins not starting**: Check Jenkins logs for errors:
128+
```bash
129+
sudo journalctl -u jenkins
130+
131+
132+
***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:***
133+
134+
- [LinkedIn](https://www.linkedin.com/in/v-litesh-kumar-2094b5218)
135+
- [Mail Me](mailto:kvlitesh@gmail.com)
136+
137+
Let's dive into Jenkins together and streamline your software delivery!
138+
139+
**Happy CI/CD-ing!** 🚀
140+
141+
142+
143+

0 commit comments

Comments
 (0)