DevOps Tools: Docker, Jenkins, and Git Cheat Sheet
Ashwini DaveSeptember 9th, 2024Last Updated: September 11th, 2024
0 243 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.
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).
Pro Git Book: https://git-scm.com/book/en/v2 – This free, open-source book is a great resource for mastering Git, from basic concepts to advanced techniques.
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
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.