-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from bobbyiliev/updates-for-2024
Updates for 2024
- Loading branch information
Showing
18 changed files
with
3,007 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,106 @@ | ||
# Introduction to Docker | ||
# Chapter 1: Introduction to Docker | ||
|
||
It is more likely than not that **Docker** and containers are going to be part of your IT career in one way or another. | ||
## What is Docker? | ||
|
||
After reading this eBook, you will have a good understanding of the following: | ||
Docker is an open-source platform that automates the deployment, scaling, and management of applications using containerization technology. It allows developers to package applications and their dependencies into standardized units called containers, which can run consistently across different environments. | ||
|
||
* What is Docker | ||
* What are containers | ||
* What are Docker Images | ||
* What is Docker Hub | ||
* How to installing Docker | ||
* How to work with Docker containers | ||
* How to work with Docker images | ||
* What is a Dockerfile | ||
* How to deploy a Dockerized app | ||
* Docker networking | ||
* What is Docker Swarm | ||
* How to deploy and manage a Docker Swarm Cluster | ||
### Key Concepts: | ||
|
||
I'll be using **DigitalOcean** for all of the demos, so I would strongly encourage you to create a **DigitalOcean** account to follow along. You would learn more by doing! | ||
1. **Containerization**: A lightweight form of virtualization that packages applications and their dependencies together. | ||
2. **Docker Engine**: The runtime that allows you to build and run containers. | ||
3. **Docker Image**: A read-only template used to create containers. | ||
4. **Docker Container**: A runnable instance of a Docker image. | ||
5. **Docker Hub**: A cloud-based registry for storing and sharing Docker images. | ||
|
||
To make things even better you can use my referral link to get a free $100 credit that you could use to deploy your virtual machines and test the guide yourself on a few **DigitalOcean servers**: | ||
## Why Use Docker? | ||
|
||
**[DigitalOcean $100 Free Credit](https://m.do.co/c/2a9bba940f39)** | ||
Docker offers numerous advantages for developers and operations teams: | ||
|
||
Once you have your account here's how to deploy your first Droplet/server: | ||
1. **Consistency**: Ensures applications run the same way in development, testing, and production environments. | ||
2. **Isolation**: Containers are isolated from each other and the host system, improving security and reducing conflicts. | ||
3. **Portability**: Containers can run on any system that supports Docker, regardless of the underlying infrastructure. | ||
4. **Efficiency**: Containers share the host system's OS kernel, making them more lightweight than traditional virtual machines. | ||
5. **Scalability**: Easy to scale applications horizontally by running multiple containers. | ||
6. **Version Control**: Docker images can be versioned, allowing for easy rollbacks and updates. | ||
|
||
[https://www.digitalocean.com/docs/droplets/how-to/create/](https://www.digitalocean.com/docs/droplets/how-to/create/) | ||
## Docker Architecture | ||
|
||
I'll be using **Ubuntu 21.04** so I would recommend that you stick to the same so you could follow along. | ||
Docker uses a client-server architecture: | ||
|
||
However you can run Docker on almost any operating system including Linux, Windows, Mac, BSD and etc. | ||
1. **Docker Client**: The primary way users interact with Docker through the command line interface (CLI). | ||
2. **Docker Host**: The machine running the Docker daemon (dockerd). | ||
3. **Docker Daemon**: Manages Docker objects like images, containers, networks, and volumes. | ||
4. **Docker Registry**: Stores Docker images (e.g., Docker Hub). | ||
|
||
Here's a simplified diagram of the Docker architecture: | ||
|
||
## What is a container? | ||
``` | ||
┌─────────────┐ ┌─────────────────────────────────────┐ | ||
│ Docker CLI │ │ Docker Host │ | ||
│ (docker) │◄───►│ ┌────────────┐ ┌───────────┐ │ | ||
└─────────────┘ │ │ Docker │ │ Containers│ │ | ||
│ │ Daemon │◄────►│ and │ │ | ||
│ │ (dockerd) │ │ Images │ │ | ||
│ └────────────┘ └───────────┘ │ | ||
└─────────────────────────────────────┘ | ||
▲ | ||
│ | ||
▼ | ||
┌─────────────────────┐ | ||
│ Docker Registry │ | ||
│ (Docker Hub) │ | ||
└─────────────────────┘ | ||
``` | ||
|
||
According to the official definition from the [docker.com](docker.com) website, a container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings. | ||
## Containers vs. Virtual Machines | ||
|
||
Container images become containers at runtime and in the case of Docker containers - images become containers when they run on Docker Engine. Available for both Linux and Windows-based applications, containerized software will always run the same, regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging. | ||
While both containers and virtual machines (VMs) are used for isolating applications, they differ in several key aspects: | ||
|
||
 | ||
| Aspect | Containers | Virtual Machines | | ||
|-----------------|---------------------------------------|-------------------------------------| | ||
| OS | Share host OS kernel | Run full OS and kernel | | ||
| Resource Usage | Lightweight, minimal overhead | Higher resource usage | | ||
| Boot Time | Seconds | Minutes | | ||
| Isolation | Process-level isolation | Full isolation | | ||
| Portability | Highly portable across different OSes | Less portable, OS-dependent | | ||
| Performance | Near-native performance | Slight performance overhead | | ||
| Storage | Typically smaller (MBs) | Larger (GBs) | | ||
|
||
## What is a Docker image? | ||
## Basic Docker Workflow | ||
|
||
A **Docker Image** is just a template used to build a running Docker Container, similar to the ISO files and Virtual Machines. The containers are essentially the running instance of an image. Images are used to share containerized applications. Collections of images are stored in registries like [DockerHub](https://hub.docker.com/) or private registries. | ||
1. **Build**: Create a Dockerfile that defines your application and its dependencies. | ||
2. **Ship**: Push your Docker image to a registry like Docker Hub. | ||
3. **Run**: Pull the image and run it as a container on any Docker-enabled host. | ||
|
||
 | ||
Here's a simple example of this workflow: | ||
|
||
```bash | ||
# Build an image | ||
docker build -t myapp:v1 . | ||
|
||
## What is Docker Hub? | ||
# Ship the image to Docker Hub | ||
docker push username/myapp:v1 | ||
|
||
DockerHub is the default **Docker image registry** where we can store our **Docker images**. You can think of it as GitHub for Git projects. | ||
# Run the container | ||
docker run -d -p 8080:80 username/myapp:v1 | ||
``` | ||
|
||
Here's a link to the Docker Hub: | ||
## Docker Components | ||
|
||
[https://hub.docker.com](https://hub.docker.com) | ||
1. **Dockerfile**: A text file containing instructions to build a Docker image. | ||
2. **Docker Compose**: A tool for defining and running multi-container Docker applications. | ||
3. **Docker Swarm**: Docker's native clustering and orchestration solution. | ||
4. **Docker Network**: Facilitates communication between Docker containers. | ||
5. **Docker Volume**: Provides persistent storage for container data. | ||
|
||
You can sign up for a free account. That way you could push your Docker images from your local machine to DockerHub. | ||
## Use Cases for Docker | ||
|
||
1. **Microservices Architecture**: Deploy and scale individual services independently. | ||
2. **Continuous Integration/Continuous Deployment (CI/CD)**: Streamline development and deployment processes. | ||
3. **Development Environments**: Create consistent development environments across teams. | ||
4. **Application Isolation**: Run multiple versions of an application on the same host. | ||
5. **Legacy Application Migration**: Containerize legacy applications for easier management and deployment. | ||
|
||
## Conclusion | ||
|
||
Docker has revolutionized how applications are developed, shipped, and run. By providing a standardized way to package and deploy applications, Docker addresses many of the challenges faced in modern software development and operations. As we progress through this book, we'll dive deeper into each aspect of Docker, providing you with the knowledge and skills to leverage this powerful technology effectively. |
Oops, something went wrong.