Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
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
/
container.md
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
13 lines (7 loc) · 1.91 KB
master
Breadcrumbs
docker_practice
/
basic_concept
/
container.md
Copy path
Top
File metadata and controls
Code
Blame
13 lines (7 loc) · 1.91 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
#
Docker
容器
镜像
(
`Image`
)
和容器
(
`Container`
)
的关系
,
就像是面向对象程序设计中的
`类`
和
`实例`
一样
,
镜像是静态的定义
,
容器是镜像运行时的实体
。
容器可以被创建
、
启动
、
停止
、
删除
、
暂停等
。
容器的实质是进程
,
但与直接在宿主执行的进程不同
,
容器进程运行于属于自己的独立的
[
命名空间
](
https
:
//en.wikipedia.org/wiki/Linux_namespaces)。因此容器可以拥有自己的 `root` 文件系统、自己的网络配置、自己的进程空间,甚至自己的用户 ID 空间。容器内的进程是运行在一个隔离的环境里,使用起来,就好像是在一个独立于宿主的系统下操作一样。这种特性使得容器封装的应用比直接在宿主运行更加安全。也因为这种隔离的特性,很多人初学 Docker 时常常会混淆容器和虚拟机。
前面讲过镜像使用的是分层存储
,
容器也是如此
。
每一个容器运行时
,
是以镜像为基础层
,
在其上创建一个当前容器的存储层
,
我们可以称这个为容器运行时读写而准备的存储层为
*
*
容器存储层
*
*
。
容器存储层的生存周期和容器一样
,
容器消亡时
,
容器存储层也随之消亡
。
因此
,
任何保存于容器存储层的信息都会随容器删除而丢失
。
按照
Docker
最佳实践的要求
,
容器不应该向其存储层内写入任何数据
,
容器存储层要保持无状态化
。
所有的文件写入操作
,
都应该使用
[
数据卷
(
Volume
)](..
/
data_management
/
volume
.
md
)、
或者
[
绑定宿主目录
](..
/
data_management
/
bind
-
mounts
.
md
),
在这些位置的读写会跳过容器存储层
,
直接对宿主
(
或网络存储
)
发生读写
,
其性能和稳定性更高
。
数据卷的生存周期独立于容器
,
容器消亡
,
数据卷不会消亡
。
因此
,
使用数据卷后
,
容器删除或者重新运行之后
,
数据却不会丢失
。
You can’t perform that action at this time.