Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
unsignedcpp
docker_practice
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
docker_practice
/
basic_concept
/
image.md
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
15 lines (8 loc) · 2.07 KB
master
Breadcrumbs
docker_practice
/
basic_concept
/
image.md
Copy path
Top
File metadata and controls
Code
Blame
15 lines (8 loc) · 2.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#
Docker
镜像
我们都知道
,
操作系统分为
*
*
内核
*
*
和
*
*
用户空间
*
*
。
对于
`Linux`
而言
,
内核启动后
,
会挂载
`root`
文件系统为其提供用户空间支持
。
而
*
*
Docker
镜像
*
*
(
`Image`
),
就相当于是一个
`root`
文件系统
。
比如官方镜像
`ubuntu:18.04`
就包含了完整的一套
Ubuntu
18.04
最小系统的
`root`
文件系统
。
*
*
Docker
镜像
*
*
是一个特殊的文件系统
,
除了提供容器运行时所需的程序
、
库
、
资源
、
配置等文件外
,
还包含了一些为运行时准备的一些配置参数
(
如匿名卷
、
环境变量
、
用户等
)。
镜像
*
*
不包含
*
*
任何动态数据
,
其内容在构建之后也不会被改变
。
##
分层存储
因为镜像包含操作系统完整的
`root`
文件系统
,
其体积往往是庞大的
,
因此在
Docker
设计时
,
就充分利用
[
Union
FS
](
https
:
//en.wikipedia.org/wiki/Union_mount) 的技术,将其设计为分层存储的架构。所以严格来说,镜像并非是像一个 `ISO` 那样的打包文件,镜像只是一个虚拟的概念,其实际体现并非由一个文件组成,而是由一组文件系统组成,或者说,由多层文件系统联合组成。
镜像构建时
,
会一层层构建
,
前一层是后一层的基础
。
每一层构建完就不会再发生改变
,
后一层上的任何改变只发生在自己这一层
。
比如
,
删除前一层文件的操作
,
实际不是真的删除前一层的文件
,
而是仅在当前层标记为该文件已删除
。
在最终容器运行的时候
,
虽然不会看到这个文件
,
但是实际上该文件会一直跟随镜像
。
因此
,
在构建镜像的时候
,
需要额外小心
,
每一层尽量只包含该层需要添加的东西
,
任何额外的东西应该在该层构建结束前清理掉
。
分层存储的特征还使得镜像的复用
、
定制变的更为容易
。
甚至可以用之前构建好的镜像作为基础层
,
然后进一步添加新的层
,
以定制自己所需的内容
,
构建新的镜像
。
关于镜像构建
,
将会在后续相关章节中做进一步的讲解
。
You can’t perform that action at this time.