初识Dockerfile

来源:互联网 发布:2016淘宝客pid怎么看 编辑:程序博客网 时间:2024/06/07 07:00


原文链接: 点击打开链接


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.




 




0 0
原创粉丝点击