Getting Started with Docker: A Beginner's Guide to Understanding and Using Docker
Table of contents
- Introduction
- what is Docker?
- Why is Docker needed?
- Benefits of Docker
- Docker architecture
- 1. Docker Client
- 2. Docker Host
- 3. Docker Registry
- What is a Docker engine?
- Docker vs Virtual Machine
- Installation of docker on Ubuntu
- Step 1: Update Package Index
- Step 2: Install Docker Engine
- Step 3: Verify Installation
- Step 4: Run Docker Without Sudo (Recommended for convenience)
- What is DockerFile, Docker Image, and Docker Container
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
Isolation*: Encapsulates apps and dependencies, ensuring consistent behavior.*
Efficiency*: Lightweight containers share the OS kernel, reducing overhead.*
Portability*: Eliminates "works on my machine" issues, and runs on any Docker-supporting system.*
Consistency*: Maintains uniform environments from development to production.*
Scalability*: Easily scales by deploying multiple containers.*
Rapid Deployment*: Quickly spins up/down containers for faster updates.*
Version Control*: Images can be versioned for easy rollback.*
Resource Utilization*: Maximizes server efficiency through shared OS components.*
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
Docker d (Docker Daemon)*: This is the background service that manages containers. It builds, runs, and monitors containers on a system.*
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.*
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
Aspect | Docker | Virtual Machines (VMs) |
Architecture | Containerization | Hypervisor |
Performance | Lightweight, shares OS | Heavier, runs complete OS |
Isolation | Process-level isolation | Full OS-level isolation |
Resource Usage | Efficient, shares OS resources | Less efficient, more overhead |
Startup Time | Seconds | Minutes |
Portability | High | Less portable |
Resource Overhead | Lower | Higher |
Image Size | Smaller | Larger |
Deployment Speed | Faster, due to sharing OS | Slower, due to booting full OS |
Scaling | Faster, due to less overhead | Slower, due to more overhead |
Use Case | Microservices, lightweight apps | Legacy 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
Step 4: Run Docker Without Sudo (Recommended for convenience)
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