DevOpsAutomationNotes

DevOps Notes

Introduction to DevOps

DevOps is a set of practices that combines software development (Dev) and IT operations (Ops). The main goal is to shorten the systems development life cycle and provide continuous delivery with high software quality.

Phases of DevOps

  1. Planning: Define the project scope, requirements, and objectives.
  2. Development: Write and build the code.
  3. Testing: Validate the code through automated and manual testing.
  4. Deployment: Release the code to production environments.
  5. Monitoring: Continuously monitor the application and infrastructure for performance and issues.
  6. Feedback: Gather feedback from users and stakeholders to improve the product.
  7. Operations: Manage the infrastructure and ensure system reliability.
  8. Security: Integrate security practices throughout the DevOps lifecycle (DevSecOps).
  9. Collaboration: Foster a culture of collaboration between teams to enhance communication and efficiency.

Key Concepts

Docker

Docker is a platform that enables developers to automate the deployment of applications inside lightweight, portable containers. Containers package an application and its dependencies, ensuring consistency across different environments.

Why Use Docker?

Key Concepts

Basic Commands

A Dockerfile is a text file that contains instructions for building a Docker image. It defines the environment in which an application runs, including the base image, dependencies, and configuration.

Base Image

A base image is the starting point for building a Docker image. It can be an official image from Docker Hub or a custom image. Base images provide the necessary environment and libraries for your application to run.

Types of Base Images

  1. Full OS Base Image: Contains a complete operating system (e.g., Ubuntu, CentOS).
  2. Language Runtime Image: Includes a specific programming language runtime (e.g., Python, Node.js).
  3. Scratch: An empty base image used to build minimal images from scratch, often used for small, single-purpose applications.

    Multi-Stage Builds

    Multi-stage builds allow you to create smaller, more efficient Docker images by separating the build environment from the runtime environment. This reduces the final image size by excluding unnecessary build dependencies.

Basic Dockerfile Structure

# Use an official base image
FROM <base_image>
# Set the working directory
WORKDIR /app
# Copy files from the host to the container
COPY . .
# Install dependencies
RUN pip install -r requirements.txt
# Expose a port
EXPOSE 5000
# Define the command to run the application
CMD ["python", "app.py"]

Example Dockerfile

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]

Example docker-compose.yml

version: '3'
services:
  web:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - .:/app
  db:
    image: postgres:latest
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password