| Invalid Date
字数 0阅读时长 1 分钟
General guidelines and recommendations

Create ephemeral containers

The image defined by your Dockerfile should generate containers that are as ephemeral as possible. By “ephemeral”, we mean that the container can be stopped and destroyed, then rebuilt and replaced with an absolute minimum set up and configuration.
Refer to Processes under The Twelve-factor App methodology to get a feel for the motivations of running containers in such a stateless fashion.

Understand build context

When you issue a docker build command, the current working directory is called the build context. By default, the Dockerfile is assumed to be located here, but you can specify a different location with the file flag (-f). Regardless of where the Dockerfile actually lives, all recursive contents of files and directories in the current directory are sent to the Docker daemon as the build context.
說可以用-f指定別的地方,但顯然裡面還是要有Dockerfile,這點有語意上的不清晰
 

Build context example

Create a directory for the build context and cd into it. Write “hello” into a text file named hello and create a Dockerfile that runs cat on it. Build the image from within the build context (.):

Link:dockerfile和build context不一定要在同一個資料夾

Move Dockerfile and hello into separate directories and build a second version of the image (without relying on cache from the last build). Use -f to point to the Dockerfile and specify the directory of the build context:
  • 注意-f後面接的是一個完整的路徑(相對或絕對)而不僅僅只是檔名
👉
原來Dockerfilebuild context資料夾兩者真的是可以分開的
不過因為都有具體指定路徑,所以要送去dk engine應該都辦得到,或者不確定dkfile會不會sent去dk engine,但指令一定會送過去,因為engine是執行指令的地方!
Loading...
目录