DevOps Tools: Docker, Jenkins, and Git Cheat Sheet
Ashwini DaveSeptember 9th, 2024Last Updated: September 11th, 2024
0 462 12 minutes read
Introduction
In the world of DevOps, efficiency and automation are the keys to success. Whether you’re managing containers with Docker, orchestrating them with Kubernetes, automating builds with Jenkins, or keeping track of your code with Git, each tool plays a critical role in streamlining your workflow. However, these tools can be complex, with a myriad of commands and configurations to remember. That’s where a cheat sheet comes in handy!
This guide is designed to give you a quick reference to the most essential commands and best practices for Docker, Kubernetes, Jenkins, and Git. Whether you’re a beginner looking to get started or a seasoned pro needing a refresher, this cheat sheet has something for everyone. Let’s dive in and make your DevOps journey smoother and more efficient!
Docker Cheat Sheet
Here’s a quick reference to help you navigate Docker’s core features and commands.
Installation and Setup
Platform
Info
Command
General
Install Docker Engine on your system.
Follow Docker’s Installation Guide.
Linux
Install Docker using the package manager.
sudo apt-get install docker-ce
macOS
Install Docker Desktop.
brew install –cask docker
Windows
Install Docker Desktop.
Docker Desktop for Windows
Installation And Setup
Docker Images: Pull, Build, and List Commands
Task
Command
Description
Pull an Image
docker pull <image_name>
Downloads a Docker image from Docker Hub.
Pull a Specific Version
docker pull <image_name>:<tag>
Downloads a specific version of an image (e.g., nginx:alpine).
Build an Image
docker build -t <image_name> .
Builds an image from a Dockerfile in the current directory.
Tag an Image
docker tag <image_id> <repository>:<tag>
Tags an existing image with a new repository and tag.
List Images
docker images
Displays all Docker images stored locally.
Remove an Image
docker rmi <image_id>
Deletes a specific image from local storage.
Inspect an Image
docker inspect <image_name>
Displays detailed information about an image.
Docker Images
Containers: Create, Start, Stop, and Remove
Task
Command
Description
Create and Start a Container
docker run -d –name <container_name> <image_name>
Creates and starts a container in detached mode.
Run a Container with Ports
docker run -d -p <host_port>:<container_port> <image_name>
Runs a container with specific port mapping.
Run a Container with Environment Variables
docker run -d -e <env_var>=<value> <image_name>
Runs a container with environment variables.
Start an Existing Container
docker start <container_name>
Starts a previously stopped container.
Stop a Running Container
docker stop <container_name>
Gracefully stops a running container.
Restart a Container
docker restart <container_name>
Restarts a container.
Remove a Container
docker rm <container_name>
Removes a stopped container.
View Running Containers
docker ps
Lists all currently running containers.
View All Containers
docker ps -a
Lists all containers, including stopped ones.
Inspect a Container
docker inspect <container_name>
Displays detailed information about a container.
View Container Logs
docker logs <container_name>
Displays logs generated by a container.
Containers
Docker Networking Basics: Creating and Managing Networks
Task
Command
Description
Create a Network
docker network create <network_name>
Creates a new Docker network for containers.
List Networks
docker network ls
Lists all Docker networks.
Inspect a Network
docker network inspect <network_name>
Displays detailed information about a specific network.
sudo apt-key add -<br>echo deb http://pkg.jenkins.io/debian-stable binary
Start Jenkins Service
sudo systemctl start jenkins
Starts the Jenkins service.
Check Jenkins Status
sudo systemctl status jenkins
Checks the status of the Jenkins service.
Access Jenkins Web Interface
Open http://localhost:8080 in a web browser
Access Jenkins’ web interface to complete setup.
Unlock Jenkins
Follow instructions at http://localhost:8080 to retrieve the initial admin password from /var/lib/jenkins/secrets/initialAdminPassword
Provides initial setup instructions and admin password.
Upgrade Jenkins
sudo apt-get updatesudo apt-get upgrade jenkins
Upgrades Jenkins to the latest version.
Installation And Setup
Overview of Jenkins Architecture and Components
Component
Description
Jenkins Master
The central server that coordinates the build process. It manages jobs, schedules tasks, and provides the user interface.
Jenkins Agent (Slave)
Machines configured to run build jobs dispatched by the Jenkins Master. They can run on various platforms and distribute the workload.
Build Jobs
The core unit of work in Jenkins, defining tasks such as building software or running tests.
Pipelines
Define the entire build and deployment workflow as code using a Jenkinsfile, automating complex workflows.
Plugins
Extend Jenkins’ functionality, including integrations with version control systems, build tools, and notifications.
Jenkins Architecture
Basic Jenkins Commands
Task
Command
Description
Create a New Job
Through Web UI: Click “New Item”
Initiates the creation of a new Jenkins job.
Build a Job
Click “Build Now” in job view
Starts a build of the selected job.
Delete a Job
Through Web UI: Click “Delete Project”
Removes a Jenkins job from the system.
Configure a Job
Through Web UI: Click “Configure”
Opens the configuration page for a job.
Manage Plugins
Through Web UI: Go to “Manage Jenkins””Manage Plugins”
Access the plugin management interface.
View Build History
Through Web UI: Click on a job, then “Build History”
Displays the history of builds for a job.
Pause/Resume a Job
Through Web UI: Click “Build Now” and “Pause” or “Resume”
Manages job execution to control build activity.
Schedule a Build
In Job Configuration: Set “Build Triggers”
Configures periodic builds or builds triggered by SCM changes.
Basic Jenkins Commands
Advanced Jenkins Configuration
Task
Command/Practice
Description
Create a Pipeline Job
Through Web UI: Click “New Item””Pipeline”
Creates a new pipeline job for advanced build processes.
Define a Jenkinsfile
Write Jenkinsfile in the root of your repository
Defines the build pipeline as code.
Integrate with Git
Through Web UI: Configure Source Code Management in job settings
Connects Jenkins to a Git repository for source code retrieval.
Integration with Docker
Install Docker pluginConfigure “Docker” in job settings
Allows Jenkins to build and deploy Docker containers.
Integration with Kubernetes
Install Kubernetes pluginConfigure “Kubernetes” in job settings
Manages Kubernetes clusters for scaling Jenkins builds.
Setup CI/CD Pipelines
Through Web UI: Define stages and steps in Jenkinsfile
Automates the build, test, and deployment pipeline.
Install Jenkins Plugins
Through Web UI: Go to “Manage Jenkins””Manage Plugins”
Adds functionality to Jenkins by installing plugins.
Configure Global Security
Through Web UI: Go to “Manage Jenkins””Configure Global Security”
Configures security settings, including user roles and permissions.
Backup Jenkins Configuration
Manually backup /var/lib/jenkins or use plugins like “ThinBackup”
Ensures you have a backup of Jenkins data and configurations.
Advanced Configuration
Creating and Configuring Jobs
Task
Command/Practice
Description
Create a New Freestyle Job
Through Web UI: Click “New Item””Freestyle project”
Sets up a new freestyle project for simple builds.
Create a New Pipeline Job
Through Web UI: Click “New Item””Pipeline”
Creates a new pipeline job for complex workflows.
Configure Job Triggers
In Job Configuration: Set “Build Triggers”
Defines triggers for automated builds, like SCM polling.
Set Up Build Steps
In Job Configuration: Define “Build” steps
Adds steps to build, test, and deploy the project.
Add Post-Build Actions
In Job Configuration: Define “Post-build Actions”
Configures actions to perform after the build completes.
Configure Notifications
In Job Configuration: Set “Post-build Actions”
Configures notifications to alert on build status changes.
Creating And Configuring Jobs
Managing Jenkins Pipelines: Setup and Execution
Task
Command/Practice
Description
Create a Pipeline Job
Through Web UI: Click “New Item””Pipeline”
Creates a new pipeline job for advanced build processes.
Define Stages in Jenkinsfile
Write stages in Jenkinsfile in the repository
Structures the build pipeline into distinct stages.
Execute a Pipeline Build
Click “Build Now” in the pipeline job view
Starts the pipeline build process.
View Pipeline Execution
Through Web UI: Click on a pipeline job, then “Pipeline Steps”
Monitors the execution and stages of the pipeline.
Manage Pipeline Parameters
In Pipeline Configuration: Define parameters
Configures parameters to customize pipeline builds.
Pipeline Visualization
Through Web UI: View “Pipeline Graph”
Provides a visual representation of pipeline execution.
Managing Jenkins Pipelines
Jenkinsfile: Syntax and Best Practices
Aspect
Description
Example
Basic Syntax
Defines the pipeline stages and steps in code.
pipeline { … }
Declarative Pipeline
Provides a structured format for defining pipelines.
Remove Submodule: Edit .gitmodules and .git/config to remove references, then delete the submodule directory.
Best Practices for Integration
CI/CD Pipeline Setup
Jenkins Pipeline Configuration
Define pipeline stages: Build, Test, Deploy.
Use Jenkins Pipelines (Declarative or Scripted) for automation.
Docker Integration
Build and tag Docker images in Jenkins.
Optimize Dockerfiles to reduce image size and build time.
Kubernetes Deployment
Deploy Docker containers using Kubernetes manifests or Helm charts.
Configure Kubernetes for scaling and managing applications.
Version Control with Git
Branching Strategy
Implement strategies like Gitflow or GitHub Flow for feature development and releases.
Commit and Pull Requests
Use clear commit messages and enforce code reviews through pull requests.
Merge and Conflict Resolution
Handle merge conflicts carefully and review changes before merging.
Containerization and Orchestration
Security and Optimization
Regularly scan Docker images for vulnerabilities.
Use environment variables for configuration; avoid hardcoding sensitive data.
Resource Management
Define resource requests and limits in Kubernetes to manage cluster resources efficiently.
Infrastructure as Code (IaC)
Provisioning
Use tools like Terraform or Ansible for automated infrastructure provisioning.
Version Control
Store IaC scripts in Git repositories to track changes and maintain consistency.
Continuous Testing
Integration in Pipeline
Incorporate automated tests into the Jenkins pipeline (unit, integration, end-to-end).
Test Coverage
Monitor and aim for high test coverage to identify issues early.
Monitoring and Logging
Centralized Logging
Aggregate logs using solutions like ELK Stack or Fluentd.
Performance Monitoring
Collect and visualize metrics using tools like Prometheus and Grafana.
Security Practices
Access Control
Implement role-based access controls (RBAC) in Jenkins, Docker, and Kubernetes.
Secrets Management
Use secure methods for managing secrets, such as Kubernetes Secrets or encrypted environment variables.
Conclusion
Docker, Kubernetes, Jenkins, and Git each play a crucial role in modern DevOps practices. Docker facilitates consistent environments through containerization, Kubernetes manages and scales these containers, Jenkins automates CI/CD pipelines, and Git provides robust version control and collaboration.
These tools collectively streamline development processes, ensure consistency across environments, and enhance scalability and collaboration, driving efficiency and reliability in software delivery.
Resources
Docker Ecosystem:Docker Ecosystem – Docker is a containerization platform, quickly gaining ground in DevOps as a one-stop solution for all development needs.
Docker Cleanup:Docker cleanup quick tutorial – This quick tutorial shows the different ways to rid your system of unused and unnecessary Docker files and enable smoother system performance.
Docker Documentation: https://docs.docker.com – The official Docker documentation provides comprehensive guides, tutorials, and reference material to help you get started with Docker and its advanced features.
Jenkins User Documentation: https://www.jenkins.io/doc/ – Jenkins offers detailed documentation on installing, configuring, and using Jenkins for continuous integration and continuous delivery (CI/CD).
Ashwini Dave, an accomplished digital marketer specializing in SEO and groundbreaking campaigns. With an MBA in Marketing, she crafts strategic, high-impact results. A tech enthusiast exploring AI and cutting-edge tech, Ashwini seamlessly integrates innovation into her marketing strategies. Outside the digital sphere, she is an avid traveler, finding inspiration in nature's beauty while exploring the world.