初识Dockerfile


原文链接: 点击打开链接


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

The docker build command builds an image from aDockerfile 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 thePATH as it causes the build to transfer the entire contents of your hard drive to the Docker daemon.


the Dockerfile is called Dockerfileand located in the root of the context. You use the -fflag 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 buildcommand:

$ 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 buildprocess significantly. This is indicated by theUsing cache message in the console output. (For more information, see the Build cache section) in theDockerfile 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.




 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值