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
/
container
/
run.md
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
61 lines (42 loc) · 2.21 KB
master
Breadcrumbs
docker_practice
/
container
/
run.md
Copy path
Top
File metadata and controls
Code
Blame
61 lines (42 loc) · 2.21 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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
启动容器
启动容器有两种方式
,
一种是基于镜像新建一个容器并启动
,
另外一个是将在终止状态
(
`exited`
)
的容器重新启动
。
因为
Docker
的容器实在太轻量级了
,
很多时候用户都是随时删除和新创建容器
。
##
新建并启动
所需要的命令主要为
`docker run`
。
例如
,
下面的命令输出一个
“
Hello
World
”,
之后终止容器
。
``
`bash
$ docker run ubuntu:18.04 /bin/echo 'Hello world'
Hello world
`
``
这跟在本地直接执行
`/bin/echo 'hello world'`
几乎感觉不出任何区别
。
下面的命令则启动一个
bash
终端
,
允许用户进行交互
。
``
`bash
$ docker run -t -i ubuntu:18.04 /bin/bash
root@af8bae53bdd3:/#
`
``
其中
,
`-t`
选项让Docker分配一个伪终端
(
pseudo
-
tty
)
并绑定到容器的标准输入上
,
`-i`
则让容器的标准输入保持打开
。
在交互模式下
,
用户可以通过所创建的终端来输入命令
,
例如
``
`bash
root@af8bae53bdd3:/# pwd
/
root@af8bae53bdd3:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
`
``
当利用
`docker run`
来创建容器时
,
Docker
在后台运行的标准操作包括
:
*
检查本地是否存在指定的镜像
,
不存在就从
[
registry
](..
/
repository
/
README
.
md
)
下载
*
利用镜像创建并启动一个容器
*
分配一个文件系统
,
并在只读的镜像层外面挂载一层可读写层
*
从宿主主机配置的网桥接口中桥接一个虚拟接口到容器中去
*
从地址池配置一个
ip
地址给容器
*
执行用户指定的应用程序
*
执行完毕后容器被终止
##
启动已终止容器
可以利用
`docker container start`
命令
,
直接将一个已经终止
(
`exited`
)
的容器启动运行
。
容器的核心为所执行的应用程序
,
所需要的资源都是应用程序运行所必需的
。
除此之外
,
并没有其它的资源
。
可以在伪终端中利用
`ps`
或
`top`
来查看进程信息
。
``
`bash
root@ba267838cc1b:/# ps
PID TTY TIME CMD
1 ? 00:00:00 bash
11 ? 00:00:00 ps
`
``
可见
,
容器中仅运行了指定的
bash
应用
。
这种特点使得
Docker
对资源的利用率极高
,
是货真价实的轻量级虚拟化
。
You can’t perform that action at this time.