Docker Course Lecture Notes

Jun 28, 2024

Docker Course Lecture Notes

Introduction

  • Course Objective: Gain a deep understanding of Docker concepts and practical usage in the software development process.
  • Course Structure: Mix of theoretical explanations and hands-on demos. Topics covered include what Docker is, its benefits, installation, usage, workflow with a demo project, Docker Compose, building Docker images, private Docker repositories, deployment, and data persistency.

Docker Basics

  • What is Docker: A tool for packaging applications with all dependencies and configurations into portable containers.
  • Docker vs. Virtual Machines: Docker virtualizes only the application layer, while VMs virtualize the entire OS.
  • Key Components:
    • Docker Image: Blueprint for a container, built from a Dockerfile.
    • Docker Container: A running instance of a Docker image.
    • Docker Hub: Public repository for Docker images.
    • Dockerfile: Blueprint for building Docker images.

Setting Up Docker

  • Installation: Steps vary for macOS, Windows, and Linux.
    • macOS: Simplified process via Docker Desktop.
    • Windows: Requires virtualization enabled, Docker Desktop on Windows 10, or Docker Toolbox for older versions.
    • Linux: Varies by distribution (Ubuntu, Debian, CentOS, Fedora).

Basic Docker Commands

  • Pulling Images: docker pull <image>
  • Running Containers: docker run <image>
  • Viewing Running Containers: docker ps
  • Stopping Containers: docker stop <container_id>
  • Restarting Containers: docker start <container_id>
  • Removing Containers: docker rm <container_id>
  • Viewing Images: docker images
  • Removing Images: docker rmi <image>
  • Inspecting Containers: docker exec -it <container_id> sh or docker exec -it <container_id> bash
  • Viewing Logs: docker logs <container_id>

Docker Compose

  • Overview: Tool for defining and running multi-container Docker applications.
  • Docker Compose File: YAML file defining services, networks, and volumes.
  • Commands:
    • Start Services: docker-compose up
    • Stop Services: docker-compose down

Practical Docker Use Case

  • Local Development Setup: Example of a JavaScript application using MongoDB.
    • MongoDB: Pulled and run as a Docker container.
    • Mongo Express: UI tool for MongoDB, also run in a Docker container.
  • Environment Configuration: Use Docker to manage application dependencies and services.
  • Data Persistency: Use Docker volumes to persist data across restarts.
    • Named Volumes: Easier to reference and manage compared to anonymous volumes.

Building and Deploying Docker Images

  • Dockerfile: Defines the base image, environment variables, and commands to run.
  • Building Image: docker build -t <image_name>:<tag> .
  • Tagging Image: docker tag <image_id> <repository>/<image_name>:<tag>
  • Pushing Image: docker push <repository>/<image_name>:<tag>
  • Deployment: Using Docker Compose to deploy an application with multiple services.
    • Setting up Docker Hub/Private Registry: Steps for pushing images to Docker Hub or a private Docker registry.

Docker Volumes

  • Purpose: Ensure data persistence by mounting host directories to container directories.
  • Volume Types:
    • Host Volumes: Specify exact host directory.
    • Anonymous Volumes: Automatically created by Docker.
    • Named Volumes: Managed by Docker, easier to reference.
  • Defining in Docker Compose: Volumes section to specify volume mappings.

Conclusion

  • Container Orchestration: Need for tools like Kubernetes for managing multiple containers across servers.
  • Further Learning: Dive into container orchestration with Kubernetes tutorials.

Additional Resources

  • Community and Support: Join private tech groups, Facebook communities, and follow course updates on social media.