Docker in Action 2e d - Ch1 Welcome to Docker
ToC
about this book
What is Docker?
“Hello, World”
Containers
Containers are not virtualization
Running software in containers for isolation
Shipping containers
What problems does Docker solve?
Getting organized
Improving portability
Protecting your computer
Why is Docker important?
Where and when to use Docker
Docker in the larger ecosystem
Getting help with the Docker command line
about this book
介紹 Docker、與 Linux container 觀念,分三部分:
Docker 與 container 特性,及使用他們的基本技能。
透過 Docker 進行軟體包裝與散布(distribution)。
探討 multi-container 專案與 multi-host 環境,包含 Docker Compose & Swarm,並以真實案例來建置與部署。
What is Docker
CLI 程式、background process。
軟體流通平台。
建立、執行、管理 container 的工具。
讓軟體包裝、散布、使用,能有低成本的最佳實踐。
比虛擬機器更快且更省資源。
讓使用者安裝、執行、移除程式都更容易。
Hello World (deprecated)
$ sudo apt install docker.io
$ sudo usermod -aG docker {username}
$ docker version
$ docker run dockerinaction/hello_world
最新文件
Running for the first time
Running for the first time
Run again
Run again
Containers
一種 OS-level、孤立執行環境的,虛擬化技術。
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.
https://www.docker.com/resources/what-container
Naming
jail
=> 1979 Unix-like OS,限制資源取用的執行環境。
container
=> 2005 Solaris 10,以白名單模式限制程式取用資源。
有許多書中未提及的實作,如 1982 Unix-like OS 的 chroot
,可參考 wikipedia 。
Containers are not virtualization
Virtual machine => 一個程式就要建立一台完整的虛擬機器,代表需要一個虛擬硬體,並耗費較多資源與時間來啟動 OS。
Docker container => 不虛擬硬體,而是用 container 技術,並補足其不易設定之缺點。
wikipedia : Container is OS-level virtualization.
Running software in containers for isolation
直接執行程式
透過 Docker 執行
Docker 使用 Linux 中 namespaces
跟 cgroups
來孤立每個 container。
Docker 使用下列系統特性來建立 containers:
PID namespace - Process identifiers and capabilities
UTS namespace - Host and domain name
MNT namespace - Filesystem access and structure
IPC namespace - Process communication over shared memory
NET namespace - Network access and structure
Docker 使用下列系統特性來建立 containers:
USR namespace - User names and identifiers
chroot syscall - Controls the location of the filesystem root
cgroups - Resource protection
CAP drop - Operating system feature restrictions
Security modules - Mandatory access controls
Shipping containers
運送 container 的角色 => image
,其包含要執行程式所需檔案的 snapshot。
Docker 提供了一些基本架構所需之元件( registries
& indexes
),幫助我們建構 image
。
What problems does Docker solve?
Getting organized
不用 Docker
不用 Docker
要在某個機器上,使用某套程式,其前置作業很痛苦 => 支援的 OS、安裝順序、調整設定、依賴軟體、依賴軟體的依賴軟體,還有他們的版本問題。
程式沒有隔離 => 版本不同、依賴不同、髒資料問題。
使用 Docker
使用 Docker
優雅的使用,不用考慮管理問題。
各程式獨立運作,包含它們的依賴。
Improving portability
軟體的依賴也包含了 OS 的不同。
更好的可攜性 => Docker as a runtime,比 JVM 更靈活,能執行各種語言的程式。
Protecting your computer
更安全 => 在 container 內執行程式,可控制其存取資源的權限。
Why is Docker important?
每個 Docker container 都可用一致的方式使用
就像貨櫃有各種品牌、裡面裝了各種貨物,但長寬大小皆一致,各種貨車、貨輪都可裝載。
行成生態系,改變了系統管理、開發、部署的做法;省時間、省錢、省精力。
促進社群(包含 Amazon、Microsoft、Google)使用其與 Container 技術,進而讓它們更多選擇開源專案而非自建輪子。
其特性使其成為跨平台系統的 App Store,其於原本的 Desktop 系統體系上所缺乏的。
讓大家更重視在 OS 上的孤立執行環境。
Where and when to use Docker
使用上仍受制於 OS,Docker on Windows 無法執行 macOS app。
使用 Docker 執行程式讓電腦更安全且乾淨。
仍要注意資源存取權限的控制,以及小心來路不明的 image
。
Docker Architecture
Docker uses a client-server architecture
Docker Architecture
Docker Server
Daemon( dockerd
)
listens for Docker API requests
manages Docker objects such as images, containers, networks, and volumes
can also communicate with other daemons to manage Docker services.
Docker Architecture
Docker Object
Images
a read-only template with instructions for creating a Docker container
an image is based on another image, with some additional customization
To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it
Docker Architecture
Docker Object
Containers
a runnable instance of an image
is relatively well isolated from other containers and its host machine
Docker Architecture
Client
users interact with Docker
docker
command uses the Docker API
use commands such as docker run
, the client sends these commands to dockerd
Docker Architecture
Registry
A Docker registry stores Docker images
Docker Hub is a public registry that anyone can use
You can even run your own private registry, ex: Harbor(企業等級)
Docker in the larger ecosystem
New or higher-leve problems:
container orchestration
high availability clustering
microservice life cycle management
visibility
許 Docker Plugin 或以 Docker 為核心的解決方案出現。
Docker 也貢獻了部分如 runc、libcontainerd、notary。
E.g. Kubernetes
Extensible platform for orchestrating services as containers in clustered environments.
Depends on container engines such as Docker.
Today building, customizing, or extending Kubernetes clusters is a full-time job.
This book focuses on and teaches solutions to higher-level problems using Docker alone.
Getting help with the Docker command line
善用 docker
指令。
$ docker help
$ docker help {COMMAND}
Resume presentation
Docker in Action 2e d - Ch1 Welcome to Docker
{"metaMigratedAt":"2023-06-16T02:02:10.300Z","metaMigratedFrom":"YAML","title":"Docker in Action 2e d - Ch1 Welcome to Docker","breaks":true,"slideOptions":"{\"spotlight\":{\"enabled\":true}}","contributors":"[{\"id\":\"6c61a17d-4f91-4870-8c0f-9cd2d6753e1c\",\"add\":1695,\"del\":171},{\"id\":\"b782f4d9-dbcc-42ac-b041-cf7381ba7ba9\",\"add\":8590,\"del\":3713}]"}