Getting Started with Docker: A Beginner's Guide to Understanding and Using Docker

Getting Started with Docker: A Beginner's Guide to Understanding and Using Docker

ยท

5 min read

Introduction

Discover the world of Docker, a transformative tool in the realm of DevOps! ๐Ÿณ๐Ÿš€ In this blog, we'll unravel Docker's magic, where software is packaged into portable "containers," ensuring uniform behavior across various computers. Say goodbye to compatibility concerns as Docker simplifies the deployment, testing, and sharing of applications

what is Docker?

Docker is like a digital box where you can put all the things your software needs to run. It helps programs work the same way on different computers, making them easier to share and move around.
Docker is a tool that lets you put your app and all its needed stuff (libraries, settings, etc.) into a single package called a "container." It's like a portable environment for your program, making it easy to run the same app on different computers without worrying about compatibility issues. Docker containers are lightweight and efficient, speeding up development, testing, and deployment.

Why is Docker needed?

We need Docker to solve the "it works on my machine" problem. Docker ensures that your software runs the same way everywhere, eliminating compatibility issues between different environments.

Benefits of Docker

  1. Isolation*: Encapsulates apps and dependencies, ensuring consistent behavior.*

  2. Efficiency*: Lightweight containers share the OS kernel, reducing overhead.*

  3. Portability*: Eliminates "works on my machine" issues, and runs on any Docker-supporting system.*

  4. Consistency*: Maintains uniform environments from development to production.*

  5. Scalability*: Easily scales by deploying multiple containers.*

  6. Rapid Deployment*: Quickly spins up/down containers for faster updates.*

  7. Version Control*: Images can be versioned for easy rollback.*

  8. Resource Utilization*: Maximizes server efficiency through shared OS components.*

Docker architecture

Docker Architecture

Docker follows Client-Server architecture, which includes the three main components that are Docker Client*, **Docker Host*, and *Docker Registry**.*

1. Docker Client

The Docker Client is like a friendly messenger between you and Docker. It takes your commands and requests, then talks to the Docker Engine to make things happen. Think of it as your personal assistant for managing containers and images.

2. Docker Host

Docker Host is used to provide an environment to execute and run applications. It contains the docker daemon, images, containers, networks, and storage.

3. Docker Registry

Docker Registry manages and stores the Docker images.There are two types of registries in the Docker -

Pubic Registry - Public Registry is also called as Docker hub*.*

Private Registry - It is used to share images within the enterprise.

What is a Docker engine?

Docker Engine is the core technology of Docker, consisting of three main components: Docker d (Docker Daemon), Docker CLI (Command-Line Interface), and Container d. It enables containerization, simplifying the deployment and management of applications

  1. Docker d (Docker Daemon)*: This is the background service that manages containers. It builds, runs, and monitors containers on a system.*

  2. Docker CLI (Command-Line Interface)*: This is the tool you use to interact with Docker. You send commands to Docker CLI, which then communicates with the Docker d to carry out the requested actions.*

  3. Container d*: This handles the low-level operations of managing containers, such as creating, starting, and stopping them. Dockerd uses Container d to handle container lifecycle.*

Docker vs Virtual Machine

Bitovi Academy - What is Docker

AspectDockerVirtual Machines (VMs)
ArchitectureContainerizationHypervisor
PerformanceLightweight, shares OSHeavier, runs complete OS
IsolationProcess-level isolationFull OS-level isolation
Resource UsageEfficient, shares OS resourcesLess efficient, more overhead
Startup TimeSecondsMinutes
PortabilityHighLess portable
Resource OverheadLowerHigher
Image SizeSmallerLarger
Deployment SpeedFaster, due to sharing OSSlower, due to booting full OS
ScalingFaster, due to less overheadSlower, due to more overhead
Use CaseMicroservices, lightweight appsLegacy apps, different OS needs

Installation of docker on Ubuntu

Step 1: Update Package Index

sudo apt update

Step 2: Install Docker Engine

sudo apt-get install docker.io

Step 3: Verify Installation

docker --version
sudo usermod -aG docker $USER

Remember to log out and log back in or restart your system after adding your user to the docker group for the changes to take effect.

What is DockerFile, Docker Image, and Docker Container

  • Dockerfile: A text file containing instructions to build a Docker image.

  • Docker Image: A lightweight, standalone, executable package that includes everything needed to run a piece of software.

  • Docker Container: A running instance of a Docker image, isolated and portable.

Here are some of the most commonly used commands in a Dockerfile

  • FROM: Specifies the base image to start from.

  • WORKDIR: Sets the working directory for subsequent instructions.

  • COPY: Copies files from the host to the container.

  • EXPOSE: Informs Docker that the container listens on a specific network port.

  • ENV: Sets environment variables within the container.

  • RUN: Executes a command during the image build.

  • CMD: Specifies the default command to run when a container starts.

NOTE: 3 scenario in which containers are accessible or not accessible

  • No port exposed: Container services are not accessible from outside the container environment.

  • Expose port: Specify a port for potential access, but not necessarily open to the host or external traffic.

  • -p 80:80: Map port 80 of the host to port 80 of the container, enabling external access to the container's service.

Tasks

Day 16: GitHub solution

Day 17: GitHub solution

Make a connection

Linkedin

GitHub

Twitter

ย