您的位置:首页 > 运维架构 > Docker

初识Dockerfile

2016-05-24 17:06 746 查看
原文链接: 点击打开链接

Docker通过从 Dockerfile读取指令来自动编译images, Dockerfile包含生成一个image所需要的所有命令集合,它是一个文档,使用 docker build用户可以持续执行一些命令行指令.

The 
docker
build
 command builds an image from a
Dockerfile
 and
a context.

The
build’s context is the files at a specified location 
PATH
 or 
URL
.

 
--The 
PATH
 is
a directory on your local filesystem.

 
--The 
URL
 is
a the location of a Git repository.

Warning:
Do not use your root directory, 
/
,
as the
PATH
 as
it causes the build to transfer the entire contents of your hard drive to the Docker daemon.

the 
Dockerfile
 is called 
Dockerfile
and
located in the root of the context. You use the 
-f
flag
with 
docker build
 to point to
a Dockerfile anywhere in your file system.
$ docker build -f /path/to/a/Dockerfile .


Image在编译好后的保存操作

>指定一个
image的保存路径

You can specify a repository and tag at which to save the new image if the build succeeds:
$ docker build -t shykes/myapp .

>tag多个image

To tag the image into multiple repositories after the build, add multiple 
-t
 parameters
when you run the 
build
command:
$ docker build -t shykes/myapp:1.0.2 -t shykes/myapp:latest .

加速Docker编译
Whenever
possible, Docker will re-use the intermediate images (cache), to accelerate the 
docker
build
process significantly. This is indicated by the
Using
cache
 message in the console output. (For more information, see the Build
cache section) in the
Dockerfile
 best
practices guide:

Docker
runs the instructions in a 
Dockerfile
 in
order.The first instruction must be `FROM` in
order to specify the Base
Image from which you are building.

"#" 是注释符

转义符( \ ) :

Escaping is possible by adding a 
\
 before
the variable:
\$foo
 or 
\${foo}
,
for example, will translate to
$foo
 and 
${foo}
 literals
respectively.

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dockerfile