Docker Lecture

Jun 22, 2024

Docker Lecture

Introduction to Docker

  • Importance of learning Docker for open-source contributions.
  • Docker is essential for developers, DevOps engineers, and full-stack engineers.
  • Movement towards microservices architecture and widespread adoption of Docker.
  • This is part one of a two-part Docker series.

Topics Covered in Part One

  • Problem statement Docker solves.
  • Installation of Docker on a local machine.
  • Understanding images and containers.
  • Running Ubuntu images in containers.
  • Running multiple containers.
  • Port mapping.
  • Environment variables.
  • Dockerizing a full-stack Node.js application.
  • Introduction to Docker Compose.

Problem Statement

  • Developers often struggle with setting up consistent development environments.
  • Differences in tool versions and configurations across different machines.
  • Difficulty in replicating environments for new team members or deploying to the cloud.
  • Docker solves this by using containerization to create consistent environments.

Installation

  • Install Docker CLI and Docker Desktop.
  • Commands to check installation:
    • docker --version
    • docker run hello-world

Images and Containers

  • Images: Templates for creating containers with specific software and configurations.
  • Containers: Instances of images that run applications in isolated environments.
  • Commands to interact with containers:
    • docker run to create and start a container.
    • docker ps to list running containers.
    • docker images to list images.
    • docker exec to run commands inside a running container.

Creating and Running Containers

  • Pulling and running Ubuntu image:
    • docker run -it ubuntu
  • Understanding container isolation.

Port Mapping

  • Exposing container ports to the host machine.
  • Example: Running a web server inside a container and accessing it from the host machine.
    • docker run -p 8000:8000 [IMAGE_NAME]

Environment Variables

  • Setting environment variables inside containers:
    • docker run -e KEY=VALUE [IMAGE_NAME]

Dockerizing a Node.js Application

  • Creating a simple Node.js application.
  • Writing a Dockerfile to create an image for the application.
  • Building and running the Docker image:
    • docker build -t app-name .
    • docker run -p 4000:4000 app-name

Docker Compose

  • Simplifying multi-container Docker applications.
  • Writing a docker-compose.yml file.
  • Starting multiple services with a single command:
    • docker-compose up

Conclusion

  • Importance of understanding Docker for modern development workflows.
  • Look forward to part two for advanced Docker concepts like networking and multi-stage builds.