Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff authored on 2015/02/10 09:57:52... | ... |
@@ -6,12 +6,14 @@ |
6 | 6 |
Dockerfile - automate the steps of creating a Docker image |
7 | 7 |
|
8 | 8 |
# INTRODUCTION |
9 |
+ |
|
9 | 10 |
The **Dockerfile** is a configuration file that automates the steps of creating |
10 | 11 |
a Docker image. It is similar to a Makefile. Docker reads instructions from the |
11 | 12 |
**Dockerfile** to automate the steps otherwise performed manually to create an |
12 |
-image. To build an image, create a file called **Dockerfile**. The |
|
13 |
-**Dockerfile** describes the steps taken to assemble the image. When the |
|
14 |
-**Dockerfile** has been created, call the **docker build** command, using the |
|
13 |
+image. To build an image, create a file called **Dockerfile**. |
|
14 |
+ |
|
15 |
+The **Dockerfile** describes the steps taken to assemble the image. When the |
|
16 |
+**Dockerfile** has been created, call the `docker build` command, using the |
|
15 | 17 |
path of directory that contains **Dockerfile** as the argument. |
16 | 18 |
|
17 | 19 |
# SYNOPSIS |
... | ... |
@@ -20,7 +22,7 @@ INSTRUCTION arguments |
20 | 20 |
|
21 | 21 |
For example: |
22 | 22 |
|
23 |
-FROM image |
|
23 |
+ FROM image |
|
24 | 24 |
|
25 | 25 |
# DESCRIPTION |
26 | 26 |
|
... | ... |
@@ -29,198 +31,265 @@ A Dockerfile is similar to a Makefile. |
29 | 29 |
|
30 | 30 |
# USAGE |
31 | 31 |
|
32 |
-**sudo docker build .** |
|
33 |
- -- runs the steps and commits them, building a final image |
|
34 |
- The path to the source repository defines where to find the context of the |
|
35 |
- build. The build is run by the docker daemon, not the CLI. The whole |
|
36 |
- context must be transferred to the daemon. The Docker CLI reports |
|
37 |
- "Sending build context to Docker daemon" when the context is sent to the daemon. |
|
38 |
- |
|
39 |
-**sudo docker build -t repository/tag .** |
|
40 |
- -- specifies a repository and tag at which to save the new image if the build |
|
41 |
- succeeds. The Docker daemon runs the steps one-by-one, committing the result |
|
42 |
- to a new image if necessary before finally outputting the ID of the new |
|
43 |
- image. The Docker daemon automatically cleans up the context it is given. |
|
44 |
- |
|
45 |
-Docker re-uses intermediate images whenever possible. This significantly |
|
46 |
-accelerates the *docker build* process. |
|
47 |
- |
|
32 |
+ sudo docker build . |
|
33 |
+ |
|
34 |
+ -- Runs the steps and commits them, building a final image. |
|
35 |
+ The path to the source repository defines where to find the context of the |
|
36 |
+ build. The build is run by the Docker daemon, not the CLI. The whole |
|
37 |
+ context must be transferred to the daemon. The Docker CLI reports |
|
38 |
+ `"Sending build context to Docker daemon"` when the context is sent to the |
|
39 |
+ daemon. |
|
40 |
+ |
|
41 |
+ ``` |
|
42 |
+ sudo docker build -t repository/tag . |
|
43 |
+ ``` |
|
44 |
+ |
|
45 |
+ -- specifies a repository and tag at which to save the new image if the build |
|
46 |
+ succeeds. The Docker daemon runs the steps one-by-one, committing the result |
|
47 |
+ to a new image if necessary, before finally outputting the ID of the new |
|
48 |
+ image. The Docker daemon automatically cleans up the context it is given. |
|
49 |
+ |
|
50 |
+ Docker re-uses intermediate images whenever possible. This significantly |
|
51 |
+ accelerates the *docker build* process. |
|
52 |
+ |
|
48 | 53 |
# FORMAT |
49 | 54 |
|
50 |
-**FROM image** |
|
51 |
-or |
|
52 |
-**FROM image:tag** |
|
53 |
- -- The FROM instruction sets the base image for subsequent instructions. A |
|
54 |
- valid Dockerfile must have FROM as its first instruction. The image can be any |
|
55 |
- valid image. It is easy to start by pulling an image from the public |
|
56 |
- repositories. |
|
57 |
- -- FROM must be he first non-comment instruction in Dockerfile. |
|
58 |
- -- FROM may appear multiple times within a single Dockerfile in order to create |
|
59 |
- multiple images. Make a note of the last image id output by the commit before |
|
60 |
- each new FROM command. |
|
61 |
- -- If no tag is given to the FROM instruction, latest is assumed. If the used |
|
62 |
- tag does not exist, an error is returned. |
|
55 |
+ `FROM image` |
|
56 |
+ |
|
57 |
+ `FROM image:tag` |
|
58 |
+ |
|
59 |
+ -- The **FROM** instruction sets the base image for subsequent instructions. A |
|
60 |
+ valid Dockerfile must have **FROM** as its first instruction. The image can be any |
|
61 |
+ valid image. It is easy to start by pulling an image from the public |
|
62 |
+ repositories. |
|
63 |
+ |
|
64 |
+ -- **FROM** must be the first non-comment instruction in Dockerfile. |
|
65 |
+ |
|
66 |
+ -- **FROM** may appear multiple times within a single Dockerfile in order to create |
|
67 |
+ multiple images. Make a note of the last image ID output by the commit before |
|
68 |
+ each new **FROM** command. |
|
69 |
+ |
|
70 |
+ -- If no tag is given to the **FROM** instruction, latest is assumed. If the |
|
71 |
+ used tag does not exist, an error is returned. |
|
63 | 72 |
|
64 | 73 |
**MAINTAINER** |
65 |
- --The MAINTAINER instruction sets the Author field for the generated images. |
|
74 |
+ -- **MAINTAINER** sets the Author field for the generated images. |
|
66 | 75 |
|
67 | 76 |
**RUN** |
68 |
- --RUN has two forms: |
|
69 |
- **RUN <command>** |
|
70 |
- -- (the command is run in a shell - /bin/sh -c) |
|
71 |
- **RUN ["executable", "param1", "param2"]** |
|
72 |
- --The above is executable form. |
|
73 |
- --The RUN instruction executes any commands in a new layer on top of the |
|
74 |
- current image and commits the results. The committed image is used for the next |
|
75 |
- step in Dockerfile. |
|
76 |
- --Layering RUN instructions and generating commits conforms to the core |
|
77 |
- concepts of Docker where commits are cheap and containers can be created from |
|
78 |
- any point in the history of an image. This is similar to source control. The |
|
79 |
- exec form makes it possible to avoid shell string munging. The exec form makes |
|
80 |
- it possible to RUN commands using a base image that does not contain /bin/sh. |
|
77 |
+ -- **RUN** has two forms: |
|
78 |
+ |
|
79 |
+ ``` |
|
80 |
+ # the command is run in a shell - /bin/sh -c |
|
81 |
+ RUN <command> |
|
82 |
+ |
|
83 |
+ # Executable form |
|
84 |
+ RUN ["executable", "param1", "param2"] |
|
85 |
+ ``` |
|
86 |
+ |
|
87 |
+ |
|
88 |
+ -- The **RUN** instruction executes any commands in a new layer on top of the current |
|
89 |
+ image and commits the results. The committed image is used for the next step in |
|
90 |
+ Dockerfile. |
|
91 |
+ |
|
92 |
+ -- Layering **RUN** instructions and generating commits conforms to the core |
|
93 |
+ concepts of Docker where commits are cheap and containers can be created from |
|
94 |
+ any point in the history of an image. This is similar to source control. The |
|
95 |
+ exec form makes it possible to avoid shell string munging. The exec form makes |
|
96 |
+ it possible to **RUN** commands using a base image that does not contain `/bin/sh`. |
|
81 | 97 |
|
82 | 98 |
**CMD** |
83 |
- --CMD has three forms: |
|
84 |
- **CMD ["executable", "param1", "param2"]** This is the preferred form, the |
|
85 |
- exec form. |
|
86 |
- **CMD ["param1", "param2"]** This command provides default parameters to |
|
87 |
- ENTRYPOINT) |
|
88 |
- **CMD command param1 param2** This command is run as a shell. |
|
89 |
- --There can be only one CMD in a Dockerfile. If more than one CMD is listed, only |
|
90 |
- the last CMD takes effect. |
|
91 |
- The main purpose of a CMD is to provide defaults for an executing container. |
|
99 |
+ -- **CMD** has three forms: |
|
100 |
+ |
|
101 |
+ ``` |
|
102 |
+ # Exececutable form |
|
103 |
+ CMD ["executable", "param1", "param2"]` |
|
104 |
+ |
|
105 |
+ # Provide default arguments to ENTRYPOINT |
|
106 |
+ CMD ["param1", "param2"]` |
|
107 |
+ |
|
108 |
+ # the command is run in a shell - /bin/sh -c |
|
109 |
+ CMD command param1 param2 |
|
110 |
+ ``` |
|
111 |
+ |
|
112 |
+ -- There can be only one **CMD** in a Dockerfile. If more than one **CMD** is listed, only |
|
113 |
+ the last **CMD** takes effect. |
|
114 |
+ The main purpose of a **CMD** is to provide defaults for an executing container. |
|
92 | 115 |
These defaults may include an executable, or they can omit the executable. If |
93 |
- they omit the executable, an ENTRYPOINT must be specified. |
|
94 |
- When used in the shell or exec formats, the CMD instruction sets the command to |
|
116 |
+ they omit the executable, an **ENTRYPOINT** must be specified. |
|
117 |
+ When used in the shell or exec formats, the **CMD** instruction sets the command to |
|
95 | 118 |
be executed when running the image. |
96 |
- If you use the shell form of the CMD, the <command> executes in /bin/sh -c: |
|
97 |
- **FROM ubuntu** |
|
98 |
- **CMD echo "This is a test." | wc -** |
|
99 |
- If you run <command> without a shell, then you must express the command as a |
|
119 |
+ If you use the shell form of the **CMD**, the `<command>` executes in `/bin/sh -c`: |
|
120 |
+ |
|
121 |
+ ``` |
|
122 |
+ FROM ubuntu |
|
123 |
+ CMD echo "This is a test." | wc - |
|
124 |
+ ``` |
|
125 |
+ |
|
126 |
+ -- If you run **command** without a shell, then you must express the command as a |
|
100 | 127 |
JSON array and give the full path to the executable. This array form is the |
101 |
- preferred form of CMD. All additional parameters must be individually expressed |
|
128 |
+ preferred form of **CMD**. All additional parameters must be individually expressed |
|
102 | 129 |
as strings in the array: |
103 |
- **FROM ubuntu** |
|
104 |
- **CMD ["/usr/bin/wc","--help"]** |
|
105 |
- To make the container run the same executable every time, use ENTRYPOINT in |
|
106 |
- combination with CMD. |
|
107 |
- If the user specifies arguments to docker run, the specified commands override |
|
108 |
- the default in CMD. |
|
109 |
- Do not confuse **RUN** with **CMD**. RUN runs a command and commits the result. CMD |
|
110 |
- executes nothing at build time, but specifies the intended command for the |
|
111 |
- image. |
|
130 |
+ |
|
131 |
+ ``` |
|
132 |
+ FROM ubuntu |
|
133 |
+ CMD ["/usr/bin/wc","--help"] |
|
134 |
+ ``` |
|
135 |
+ |
|
136 |
+ -- To make the container run the same executable every time, use **ENTRYPOINT** in |
|
137 |
+ combination with **CMD**. |
|
138 |
+ If the user specifies arguments to `docker run`, the specified commands |
|
139 |
+ override the default in **CMD**. |
|
140 |
+ Do not confuse **RUN** with **CMD**. **RUN** runs a command and commits the result. |
|
141 |
+ **CMD** executes nothing at build time, but specifies the intended command for |
|
142 |
+ the image. |
|
112 | 143 |
|
113 | 144 |
**EXPOSE** |
114 |
- --**EXPOSE <port> [<port>...]** |
|
115 |
- The **EXPOSE** instruction informs Docker that the container listens on the |
|
116 |
- specified network ports at runtime. Docker uses this information to |
|
117 |
- interconnect containers using links, and to set up port redirection on the host |
|
118 |
- system. |
|
145 |
+ -- `EXPOSE <port> [<port>...]` |
|
146 |
+ The **EXPOSE** instruction informs Docker that the container listens on the |
|
147 |
+ specified network ports at runtime. Docker uses this information to |
|
148 |
+ interconnect containers using links, and to set up port redirection on the host |
|
149 |
+ system. |
|
119 | 150 |
|
120 | 151 |
**ENV** |
121 |
- --**ENV <key> <value>** |
|
122 |
- The ENV instruction sets the environment variable <key> to |
|
123 |
- the value <value>. This value is passed to all future |
|
124 |
- RUN, ENTRYPOINT, and CMD instructions. This is |
|
125 |
- functionally equivalent to prefixing the command with **<key>=<value>**. The |
|
126 |
- environment variables that are set with ENV persist when a container is run |
|
127 |
- from the resulting image. Use docker inspect to inspect these values, and |
|
128 |
- change them using docker run **--env <key>=<value>.** |
|
129 |
- |
|
130 |
- Note that setting Setting **ENV DEBIAN_FRONTEND noninteractive** may cause |
|
131 |
- unintended consequences, because it will persist when the container is run |
|
132 |
- interactively, as with the following command: **docker run -t -i image bash** |
|
152 |
+ -- `ENV <key> <value>` |
|
153 |
+ The **ENV** instruction sets the environment variable <key> to |
|
154 |
+ the value `<value>`. This value is passed to all future |
|
155 |
+ RUN, **ENTRYPOINT**, and **CMD** instructions. This is |
|
156 |
+ functionally equivalent to prefixing the command with `<key>=<value>`. The |
|
157 |
+ environment variables that are set with **ENV** persist when a container is run |
|
158 |
+ from the resulting image. Use `docker inspect` to inspect these values, and |
|
159 |
+ change them using `docker run --env <key>=<value>`. |
|
160 |
+ |
|
161 |
+ Note that setting "`ENV DEBIAN_FRONTEND noninteractive`" may cause |
|
162 |
+ unintended consequences, because it will persist when the container is run |
|
163 |
+ interactively, as with the following command: `docker run -t -i image bash` |
|
133 | 164 |
|
134 | 165 |
**ADD** |
135 |
- --ADD has two forms: |
|
136 |
- **ADD <src>... <dest>** |
|
137 |
- **ADD ["<src>"... "<dest>"]** This form is required for paths containing |
|
138 |
- whitespace. |
|
139 |
- The ADD instruction copies new files, directories |
|
140 |
- or remote file URLs to the filesystem of the container at path <dest>. |
|
141 |
- Multiple <src> resources may be specified but if they are files or directories |
|
142 |
- then they must be relative to the source directory that is being built |
|
143 |
- (the context of the build). The <dest> is the absolute path, or path relative |
|
144 |
- to `WORKDIR`, into which the source is copied inside the target container. |
|
145 |
- All new files and directories are created with mode 0755 and with the uid |
|
146 |
- and gid of 0. |
|
166 |
+ -- **ADD** has two forms: |
|
167 |
+ |
|
168 |
+ ``` |
|
169 |
+ ADD <src> <dest> |
|
170 |
+ |
|
171 |
+ # Required for paths with whitespace |
|
172 |
+ ADD ["<src>", "<dest>"] |
|
173 |
+ ``` |
|
174 |
+ |
|
175 |
+ The **ADD** instruction copies new files, directories |
|
176 |
+ or remote file URLs to the filesystem of the container at path `<dest>`. |
|
177 |
+ Multiple `<src>` resources may be specified but if they are files or directories |
|
178 |
+ then they must be relative to the source directory that is being built |
|
179 |
+ (the context of the build). The `<dest>` is the absolute path, or path relative |
|
180 |
+ to **WORKDIR**, into which the source is copied inside the target container. |
|
181 |
+ All new files and directories are created with mode 0755 and with the uid |
|
182 |
+ and gid of **0**. |
|
147 | 183 |
|
148 | 184 |
**COPY** |
149 |
- --COPY has two forms: |
|
150 |
- **COPY <src>... <dest>** |
|
151 |
- **COPY ["<src>"... "<dest>"]** This form is required for paths containing |
|
152 |
- whitespace. |
|
153 |
- The COPY instruction copies new files from <src> and |
|
154 |
- adds them to the filesystem of the container at path <dest>. The <src> must be |
|
155 |
- the path to a file or directory relative to the source directory that is |
|
156 |
- being built (the context of the build) or a remote file URL. The `<dest>` is an |
|
157 |
- absolute path, or a path relative to `WORKDIR`, into which the source will |
|
158 |
- be copied inside the target container. All new files and directories are |
|
159 |
- created with mode 0755 and with the uid and gid of 0. |
|
185 |
+ -- **COPY** has two forms: |
|
186 |
+ |
|
187 |
+ ``` |
|
188 |
+ COPY <src> <dest> |
|
189 |
+ |
|
190 |
+ # Required for paths with whitespace |
|
191 |
+ COPY ["<src>", "<dest>"] |
|
192 |
+ ``` |
|
193 |
+ |
|
194 |
+ The **COPY** instruction copies new files from `<src>` and |
|
195 |
+ adds them to the filesystem of the container at path <dest>. The `<src>` must be |
|
196 |
+ the path to a file or directory relative to the source directory that is |
|
197 |
+ being built (the context of the build) or a remote file URL. The `<dest>` is an |
|
198 |
+ absolute path, or a path relative to **WORKDIR**, into which the source will |
|
199 |
+ be copied inside the target container. All new files and directories are |
|
200 |
+ created with mode **0755** and with the uid and gid of **0**. |
|
160 | 201 |
|
161 | 202 |
**ENTRYPOINT** |
162 |
- --**ENTRYPOINT** has two forms: ENTRYPOINT ["executable", "param1", "param2"] |
|
163 |
- (This is like an exec, and is the preferred form.) ENTRYPOINT command param1 |
|
164 |
- param2 (This is running as a shell.) An ENTRYPOINT helps you configure a |
|
165 |
- container that can be run as an executable. When you specify an ENTRYPOINT, |
|
166 |
- the whole container runs as if it was only that executable. The ENTRYPOINT |
|
167 |
- instruction adds an entry command that is not overwritten when arguments are |
|
168 |
- passed to docker run. This is different from the behavior of CMD. This allows |
|
169 |
- arguments to be passed to the entrypoint, for instance docker run <image> -d |
|
170 |
- passes the -d argument to the ENTRYPOINT. Specify parameters either in the |
|
171 |
- ENTRYPOINT JSON array (as in the preferred exec form above), or by using a CMD |
|
172 |
- statement. Parameters in the ENTRYPOINT are not overwritten by the docker run |
|
173 |
- arguments. Parameters specifies via CMD are overwritten by docker run |
|
174 |
- arguments. Specify a plain string for the ENTRYPOINT, and it will execute in |
|
175 |
- /bin/sh -c, like a CMD instruction: |
|
176 |
- FROM ubuntu |
|
177 |
- ENTRYPOINT wc -l - |
|
178 |
- This means that the Dockerfile's image always takes stdin as input (that's |
|
179 |
- what "-" means), and prints the number of lines (that's what "-l" means). To |
|
180 |
- make this optional but default, use a CMD: |
|
181 |
- FROM ubuntu |
|
182 |
- CMD ["-l", "-"] |
|
183 |
- ENTRYPOINT ["/usr/bin/wc"] |
|
203 |
+ -- **ENTRYPOINT** has two forms: |
|
204 |
+ |
|
205 |
+ ``` |
|
206 |
+ # executable form |
|
207 |
+ ENTRYPOINT ["executable", "param1", "param2"]` |
|
208 |
+ |
|
209 |
+ # run command in a shell - /bin/sh -c |
|
210 |
+ ENTRYPOINT command param1 param2 |
|
211 |
+ ``` |
|
212 |
+ |
|
213 |
+ -- An **ENTRYPOINT** helps you configure a |
|
214 |
+ container that can be run as an executable. When you specify an **ENTRYPOINT**, |
|
215 |
+ the whole container runs as if it was only that executable. The **ENTRYPOINT** |
|
216 |
+ instruction adds an entry command that is not overwritten when arguments are |
|
217 |
+ passed to docker run. This is different from the behavior of CMD. This allows |
|
218 |
+ arguments to be passed to the entrypoint, for instance `docker run <image> -d` |
|
219 |
+ passes the -d argument to the **ENTRYPOINT**. Specify parameters either in the |
|
220 |
+ **ENTRYPOINT** JSON array (as in the preferred exec form above), or by using a **CMD** |
|
221 |
+ statement. Parameters in the **ENTRYPOINT** are not overwritten by the docker run |
|
222 |
+ arguments. Parameters specifies via **CMD** are overwritten by docker run |
|
223 |
+ arguments. Specify a plain string for the **ENTRYPOINT**, and it will execute in |
|
224 |
+ `/bin/sh -c`, like a **CMD** instruction: |
|
225 |
+ |
|
226 |
+ ``` |
|
227 |
+ FROM ubuntu |
|
228 |
+ ENTRYPOINT wc -l - |
|
229 |
+ ``` |
|
230 |
+ |
|
231 |
+ This means that the Dockerfile's image always takes stdin as input (that's |
|
232 |
+ what "-" means), and prints the number of lines (that's what "-l" means). To |
|
233 |
+ make this optional but default, use a **CMD**: |
|
234 |
+ |
|
235 |
+ ``` |
|
236 |
+ FROM ubuntu |
|
237 |
+ CMD ["-l", "-"] |
|
238 |
+ ENTRYPOINT ["/usr/bin/wc"] |
|
239 |
+ ``` |
|
184 | 240 |
|
185 | 241 |
**VOLUME** |
186 |
- --**VOLUME ["/data"]** |
|
187 |
- The VOLUME instruction creates a mount point with the specified name and marks |
|
188 |
- it as holding externally-mounted volumes from the native host or from other |
|
189 |
- containers. |
|
242 |
+ -- `VOLUME ["/data"]` |
|
243 |
+ The **VOLUME** instruction creates a mount point with the specified name and marks |
|
244 |
+ it as holding externally-mounted volumes from the native host or from other |
|
245 |
+ containers. |
|
190 | 246 |
|
191 | 247 |
**USER** |
192 |
- -- **USER daemon** |
|
193 |
- The USER instruction sets the username or UID that is used when running the |
|
194 |
- image. |
|
248 |
+ -- `USER daemon` |
|
249 |
+ The **USER** instruction sets the username or UID that is used when running the |
|
250 |
+ image. |
|
251 |
+ |
|
252 |
+**WRKDIR** |
|
253 |
+ -- `WORKDIR /path/to/workdir` |
|
254 |
+ The **WORKDIR** instruction sets the working directory for the **RUN**, **CMD**, |
|
255 |
+ **ENTRYPOINT**, **COPY** and **ADD** Dockerfile commands that follow it. It can |
|
256 |
+ be used multiple times in a single Dockerfile. Relative paths are defined |
|
257 |
+ relative to the path of the previous **WORKDIR** instruction. For example: |
|
195 | 258 |
|
196 |
-**WORKDIR** |
|
197 |
- -- **WORKDIR /path/to/workdir** |
|
198 |
- The WORKDIR instruction sets the working directory for the **RUN**, **CMD**, **ENTRYPOINT**, **COPY** and **ADD** Dockerfile commands that follow it. |
|
199 |
- It can be used multiple times in a single Dockerfile. Relative paths are defined relative to the path of the previous **WORKDIR** instruction. For example: |
|
200 |
- **WORKDIR /a WORKDIR b WORKDIR c RUN pwd** |
|
201 |
- In the above example, the output of the **pwd** command is **a/b/c**. |
|
259 |
+ ``` |
|
260 |
+ WORKDIR /a |
|
261 |
+ WORKDIR b |
|
262 |
+ WORKDIR c |
|
263 |
+ RUN pwd |
|
264 |
+ ``` |
|
265 |
+ |
|
266 |
+ In the above example, the output of the **pwd** command is **a/b/c**. |
|
202 | 267 |
|
203 | 268 |
**ONBUILD** |
204 |
- -- **ONBUILD [INSTRUCTION]** |
|
205 |
- The ONBUILD instruction adds a trigger instruction to the image, which is |
|
206 |
- executed at a later time, when the image is used as the base for another |
|
207 |
- build. The trigger is executed in the context of the downstream build, as |
|
208 |
- if it had been inserted immediately after the FROM instruction in the |
|
209 |
- downstream Dockerfile. Any build instruction can be registered as a |
|
210 |
- trigger. This is useful if you are building an image to be |
|
211 |
- used as a base for building other images, for example an application build |
|
212 |
- environment or a daemon to be customized with a user-specific |
|
213 |
- configuration. For example, if your image is a reusable python |
|
214 |
- application builder, it requires application source code to be |
|
215 |
- added in a particular directory, and might require a build script |
|
216 |
- to be called after that. You can't just call ADD and RUN now, because |
|
217 |
- you don't yet have access to the application source code, and it |
|
218 |
- is different for each application build. Providing |
|
219 |
- application developers with a boilerplate Dockerfile to copy-paste |
|
220 |
- into their application is inefficient, error-prone, and |
|
221 |
- difficult to update because it mixes with application-specific code. |
|
222 |
- The solution is to use **ONBUILD** to register instructions in advance, to |
|
223 |
- run later, during the next build stage. |
|
269 |
+ -- `ONBUILD [INSTRUCTION]` |
|
270 |
+ The **ONBUILD** instruction adds a trigger instruction to the image, which is |
|
271 |
+ executed at a later time, when the image is used as the base for another |
|
272 |
+ build. The trigger is executed in the context of the downstream build, as |
|
273 |
+ if it had been inserted immediately after the **FROM** instruction in the |
|
274 |
+ downstream Dockerfile. Any build instruction can be registered as a |
|
275 |
+ trigger. This is useful if you are building an image to be |
|
276 |
+ used as a base for building other images, for example an application build |
|
277 |
+ environment or a daemon to be customized with a user-specific |
|
278 |
+ configuration. For example, if your image is a reusable python |
|
279 |
+ application builder, it requires application source code to be |
|
280 |
+ added in a particular directory, and might require a build script |
|
281 |
+ to be called after that. You can't just call **ADD** and **RUN** now, because |
|
282 |
+ you don't yet have access to the application source code, and it |
|
283 |
+ is different for each application build. |
|
284 |
+ |
|
285 |
+ -- Providing application developers with a boilerplate Dockerfile to copy-paste |
|
286 |
+ into their application is inefficient, error-prone, and |
|
287 |
+ difficult to update because it mixes with application-specific code. |
|
288 |
+ The solution is to use **ONBUILD** to register instructions in advance, to |
|
289 |
+ run later, during the next build stage. |
|
224 | 290 |
|
225 | 291 |
# HISTORY |
226 | 292 |
*May 2014, Compiled by Zac Dover (zdover at redhat dot com) based on docker.com Dockerfile documentation. |
293 |
+*Feb 2015, updated by Brian Goff (cpuguy83@gmail.com) for readability |