初識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.




 




發佈了241 篇原創文章 · 獲贊 63 · 訪問量 48萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章