继续docker文档的阅读
This commit is contained in:
@@ -205,3 +205,61 @@ RUN --mount=[type=<TYPE>][,option=<value>[,option=<value>]...]
|
|||||||
| `from` | `source`根路径的build stage或image name,默认情况下为build context |
|
| `from` | `source`根路径的build stage或image name,默认情况下为build context |
|
||||||
| `rw`,`readwrite` | 允许在mount后的文件系统执行写入操作,写入信息将会被丢弃 |
|
| `rw`,`readwrite` | 允许在mount后的文件系统执行写入操作,写入信息将会被丢弃 |
|
||||||
> RUN --mount=type=bind允许将context或镜像中的目录绑定到build container中,并且只有在该条RUN指令运行时,才可以访问挂载的目录。
|
> RUN --mount=type=bind允许将context或镜像中的目录绑定到build container中,并且只有在该条RUN指令运行时,才可以访问挂载的目录。
|
||||||
|
## RUN --network
|
||||||
|
控制该命令运行在哪种网络环境下,支持如下网络环境:
|
||||||
|
`syntax`:RUN --network=type
|
||||||
|
- default:运行在默认网络环境下
|
||||||
|
- none:运行在无网络访问的环境下
|
||||||
|
- host:运行在宿主机的网络环境下
|
||||||
|
## CMD
|
||||||
|
CMD命令具有三种形式:
|
||||||
|
- CMD ["executable","param1","param2"] (exec form)
|
||||||
|
- CMD ["param1","param2"] (作为ENTRYPOINT的默认参数)
|
||||||
|
- CMD command param1 param2 (shell form)
|
||||||
|
|
||||||
|
在dockerfile中,只有一条CMD指令能够生效,如果dockerfile中存在多条CMD指令,那么只有最后一条CMD指令能够生效。
|
||||||
|
CMD指令的主要作用是为执行中的容器提供默认值。该默认值可以包含可执行文件,也可以省略可执行文件,将CMD指令的参数作为ENTRYPOINT指令的默认参数。
|
||||||
|
> 如果CMD指令用于向ENTRYPOINT指令提供默认参数,那么ENTRYPOINT指令和CMD指令都要按照JSON数组的格式进行声明
|
||||||
|
|
||||||
|
当使用exec form或shell form时,CMD指令制定了镜像运行时默认执行的command。
|
||||||
|
如果使用CMD的shell form,那么command将会在`/bin/sh -c`中执行
|
||||||
|
```dockerfile
|
||||||
|
FROM ubuntu
|
||||||
|
CMD echo "This is a test." | wc -
|
||||||
|
```
|
||||||
|
如果想不在shell中运行CMD,那么必须将command作为JSON ARRAY传递,并且指定可执行文件的full path。
|
||||||
|
```dockerfile
|
||||||
|
FROM ubuntu
|
||||||
|
CMD ["/usr/bin/wc","--help"]
|
||||||
|
```
|
||||||
|
如果用户在`docker run`命令中指定了参数,那么参数将会覆盖CMD命令提供的默认值。
|
||||||
|
## LABEL
|
||||||
|
LABEL命令的格式如下所示:
|
||||||
|
```dockerfile
|
||||||
|
LABEL <key>=<value> <key>=<value> <key>=<value> ...
|
||||||
|
```
|
||||||
|
LABEL命令向image中添加元数据,一个LABEL是一个key-value对,如果想要在LABEL value中包含空格,需要加入双引号或是转义符:
|
||||||
|
```dockerfile
|
||||||
|
LABEL "com.example.vendor"="ACME Incorporated"
|
||||||
|
LABEL com.example.label-with-value="foo"
|
||||||
|
LABEL version="1.0"
|
||||||
|
LABEL description="This text illustrates \
|
||||||
|
that label-values can span multiple lines."
|
||||||
|
```
|
||||||
|
可以在同一行LABEL命令中指定多个key-value pair。
|
||||||
|
**在父镜像中定义的LABEL能被继承,如果父镜像和子镜像中都定义了相同的LABEL,那么最近的LABEL定义将会覆盖父镜像的同名LABEL。
|
||||||
|
如果要查看一个镜像的LABEL,可以通过`docker image inspect`命令来进行查看,可以通过`--format`指定显示的格式:
|
||||||
|
```shell
|
||||||
|
# docker image inspect --format='' myimage
|
||||||
|
```
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"com.example.vendor": "ACME Incorporated",
|
||||||
|
"com.example.label-with-value": "foo",
|
||||||
|
"version": "1.0",
|
||||||
|
"description": "This text illustrates that label-values can span multiple lines.",
|
||||||
|
"multi.label1": "value1",
|
||||||
|
"multi.label2": "value2",
|
||||||
|
"other": "value3"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user