Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -65,31 +65,37 @@ a subdirectory inside the repository that will be used as a build context. |
| 65 | 65 |
For example, run this command to use a directory called `docker` in the branch |
| 66 | 66 |
`container`: |
| 67 | 67 |
|
| 68 |
- $ docker build https://github.com/docker/rootfs.git#container:docker |
|
| 68 |
+```bash |
|
| 69 |
+$ docker build https://github.com/docker/rootfs.git#container:docker |
|
| 70 |
+``` |
|
| 69 | 71 |
|
| 70 | 72 |
The following table represents all the valid suffixes with their build |
| 71 | 73 |
contexts: |
| 72 | 74 |
|
| 73 |
-Build Syntax Suffix | Commit Used | Build Context Used |
|
| 74 |
-`myrepo.git` | `refs/heads/master` | `/` |
|
| 75 |
-`myrepo.git#mytag` | `refs/tags/mytag` | `/` |
|
| 76 |
-`myrepo.git#mybranch` | `refs/heads/mybranch` | `/` |
|
| 77 |
-`myrepo.git#abcdef` | `sha1 = abcdef` | `/` |
|
| 78 |
-`myrepo.git#:myfolder` | `refs/heads/master` | `/myfolder` |
|
| 79 |
-`myrepo.git#master:myfolder` | `refs/heads/master` | `/myfolder` |
|
| 80 |
-`myrepo.git#mytag:myfolder` | `refs/tags/mytag` | `/myfolder` |
|
| 81 |
-`myrepo.git#mybranch:myfolder` | `refs/heads/mybranch` | `/myfolder` |
|
| 82 |
-`myrepo.git#abcdef:myfolder` | `sha1 = abcdef` | `/myfolder` |
|
| 75 |
+Build Syntax Suffix | Commit Used | Build Context Used |
|
| 76 |
+--------------------------------|-----------------------|------------------- |
|
| 77 |
+`myrepo.git` | `refs/heads/master` | `/` |
|
| 78 |
+`myrepo.git#mytag` | `refs/tags/mytag` | `/` |
|
| 79 |
+`myrepo.git#mybranch` | `refs/heads/mybranch` | `/` |
|
| 80 |
+`myrepo.git#abcdef` | `sha1 = abcdef` | `/` |
|
| 81 |
+`myrepo.git#:myfolder` | `refs/heads/master` | `/myfolder` |
|
| 82 |
+`myrepo.git#master:myfolder` | `refs/heads/master` | `/myfolder` |
|
| 83 |
+`myrepo.git#mytag:myfolder` | `refs/tags/mytag` | `/myfolder` |
|
| 84 |
+`myrepo.git#mybranch:myfolder` | `refs/heads/mybranch` | `/myfolder` |
|
| 85 |
+`myrepo.git#abcdef:myfolder` | `sha1 = abcdef` | `/myfolder` |
|
| 83 | 86 |
|
| 84 | 87 |
Instead of specifying a context, you can pass a single Dockerfile in the `URL` |
| 85 | 88 |
or pipe the file in via `STDIN`. To pipe a Dockerfile from `STDIN`: |
| 86 | 89 |
|
| 87 |
- $ docker build - < Dockerfile |
|
| 90 |
+```bash |
|
| 91 |
+$ docker build - < Dockerfile |
|
| 92 |
+``` |
|
| 88 | 93 |
|
| 89 | 94 |
With Powershell on Windows, you can run: |
| 90 | 95 |
|
| 91 |
- Get-Content Dockerfile | docker build - |
|
| 96 |
+```powershell |
|
| 97 |
+Get-Content Dockerfile | docker build - |
|
| 98 |
+``` |
|
| 92 | 99 |
|
| 93 | 100 |
If you use STDIN or specify a `URL`, the system places the contents into a file |
| 94 | 101 |
called `Dockerfile`, and any `-f`, `--file` option is ignored. In this |
| ... | ... |
@@ -121,16 +127,19 @@ build fails, a non-zero failure code will be returned. |
| 121 | 121 |
There should be informational output of the reason for failure output to |
| 122 | 122 |
`STDERR`: |
| 123 | 123 |
|
| 124 |
- $ docker build -t fail . |
|
| 125 |
- Sending build context to Docker daemon 2.048 kB |
|
| 126 |
- Sending build context to Docker daemon |
|
| 127 |
- Step 1 : FROM busybox |
|
| 128 |
- ---> 4986bf8c1536 |
|
| 129 |
- Step 2 : RUN exit 13 |
|
| 130 |
- ---> Running in e26670ec7a0a |
|
| 131 |
- INFO[0000] The command [/bin/sh -c exit 13] returned a non-zero code: 13 |
|
| 132 |
- $ echo $? |
|
| 133 |
- 1 |
|
| 124 |
+```bash |
|
| 125 |
+$ docker build -t fail . |
|
| 126 |
+ |
|
| 127 |
+Sending build context to Docker daemon 2.048 kB |
|
| 128 |
+Sending build context to Docker daemon |
|
| 129 |
+Step 1 : FROM busybox |
|
| 130 |
+ ---> 4986bf8c1536 |
|
| 131 |
+Step 2 : RUN exit 13 |
|
| 132 |
+ ---> Running in e26670ec7a0a |
|
| 133 |
+INFO[0000] The command [/bin/sh -c exit 13] returned a non-zero code: 13 |
|
| 134 |
+$ echo $? |
|
| 135 |
+1 |
|
| 136 |
+``` |
|
| 134 | 137 |
|
| 135 | 138 |
See also: |
| 136 | 139 |
|
| ... | ... |
@@ -140,31 +149,34 @@ See also: |
| 140 | 140 |
|
| 141 | 141 |
### Build with PATH |
| 142 | 142 |
|
| 143 |
- $ docker build . |
|
| 144 |
- Uploading context 10240 bytes |
|
| 145 |
- Step 1 : FROM busybox |
|
| 146 |
- Pulling repository busybox |
|
| 147 |
- ---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/ |
|
| 148 |
- Step 2 : RUN ls -lh / |
|
| 149 |
- ---> Running in 9c9e81692ae9 |
|
| 150 |
- total 24 |
|
| 151 |
- drwxr-xr-x 2 root root 4.0K Mar 12 2013 bin |
|
| 152 |
- drwxr-xr-x 5 root root 4.0K Oct 19 00:19 dev |
|
| 153 |
- drwxr-xr-x 2 root root 4.0K Oct 19 00:19 etc |
|
| 154 |
- drwxr-xr-x 2 root root 4.0K Nov 15 23:34 lib |
|
| 155 |
- lrwxrwxrwx 1 root root 3 Mar 12 2013 lib64 -> lib |
|
| 156 |
- dr-xr-xr-x 116 root root 0 Nov 15 23:34 proc |
|
| 157 |
- lrwxrwxrwx 1 root root 3 Mar 12 2013 sbin -> bin |
|
| 158 |
- dr-xr-xr-x 13 root root 0 Nov 15 23:34 sys |
|
| 159 |
- drwxr-xr-x 2 root root 4.0K Mar 12 2013 tmp |
|
| 160 |
- drwxr-xr-x 2 root root 4.0K Nov 15 23:34 usr |
|
| 161 |
- ---> b35f4035db3f |
|
| 162 |
- Step 3 : CMD echo Hello world |
|
| 163 |
- ---> Running in 02071fceb21b |
|
| 164 |
- ---> f52f38b7823e |
|
| 165 |
- Successfully built f52f38b7823e |
|
| 166 |
- Removing intermediate container 9c9e81692ae9 |
|
| 167 |
- Removing intermediate container 02071fceb21b |
|
| 143 |
+```bash |
|
| 144 |
+$ docker build . |
|
| 145 |
+ |
|
| 146 |
+Uploading context 10240 bytes |
|
| 147 |
+Step 1 : FROM busybox |
|
| 148 |
+Pulling repository busybox |
|
| 149 |
+ ---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/ |
|
| 150 |
+Step 2 : RUN ls -lh / |
|
| 151 |
+ ---> Running in 9c9e81692ae9 |
|
| 152 |
+total 24 |
|
| 153 |
+drwxr-xr-x 2 root root 4.0K Mar 12 2013 bin |
|
| 154 |
+drwxr-xr-x 5 root root 4.0K Oct 19 00:19 dev |
|
| 155 |
+drwxr-xr-x 2 root root 4.0K Oct 19 00:19 etc |
|
| 156 |
+drwxr-xr-x 2 root root 4.0K Nov 15 23:34 lib |
|
| 157 |
+lrwxrwxrwx 1 root root 3 Mar 12 2013 lib64 -> lib |
|
| 158 |
+dr-xr-xr-x 116 root root 0 Nov 15 23:34 proc |
|
| 159 |
+lrwxrwxrwx 1 root root 3 Mar 12 2013 sbin -> bin |
|
| 160 |
+dr-xr-xr-x 13 root root 0 Nov 15 23:34 sys |
|
| 161 |
+drwxr-xr-x 2 root root 4.0K Mar 12 2013 tmp |
|
| 162 |
+drwxr-xr-x 2 root root 4.0K Nov 15 23:34 usr |
|
| 163 |
+ ---> b35f4035db3f |
|
| 164 |
+Step 3 : CMD echo Hello world |
|
| 165 |
+ ---> Running in 02071fceb21b |
|
| 166 |
+ ---> f52f38b7823e |
|
| 167 |
+Successfully built f52f38b7823e |
|
| 168 |
+Removing intermediate container 9c9e81692ae9 |
|
| 169 |
+Removing intermediate container 02071fceb21b |
|
| 170 |
+``` |
|
| 168 | 171 |
|
| 169 | 172 |
This example specifies that the `PATH` is `.`, and so all the files in the |
| 170 | 173 |
local directory get `tar`d and sent to the Docker daemon. The `PATH` specifies |
| ... | ... |
@@ -182,7 +194,9 @@ you must use `--rm=false`. This does not affect the build cache. |
| 182 | 182 |
|
| 183 | 183 |
### Build with URL |
| 184 | 184 |
|
| 185 |
- $ docker build github.com/creack/docker-firefox |
|
| 185 |
+```bash |
|
| 186 |
+$ docker build github.com/creack/docker-firefox |
|
| 187 |
+``` |
|
| 186 | 188 |
|
| 187 | 189 |
This will clone the GitHub repository and use the cloned repository as context. |
| 188 | 190 |
The Dockerfile at the root of the repository is used as Dockerfile. Note that |
| ... | ... |
@@ -191,39 +205,46 @@ scheme. |
| 191 | 191 |
|
| 192 | 192 |
### Build with - |
| 193 | 193 |
|
| 194 |
- $ docker build - < Dockerfile |
|
| 194 |
+```bash |
|
| 195 |
+$ docker build - < Dockerfile |
|
| 196 |
+``` |
|
| 195 | 197 |
|
| 196 | 198 |
This will read a Dockerfile from `STDIN` without context. Due to the lack of a |
| 197 | 199 |
context, no contents of any local directory will be sent to the Docker daemon. |
| 198 | 200 |
Since there is no context, a Dockerfile `ADD` only works if it refers to a |
| 199 | 201 |
remote URL. |
| 200 | 202 |
|
| 201 |
- $ docker build - < context.tar.gz |
|
| 203 |
+```bash |
|
| 204 |
+$ docker build - < context.tar.gz |
|
| 205 |
+``` |
|
| 202 | 206 |
|
| 203 | 207 |
This will build an image for a compressed context read from `STDIN`. Supported |
| 204 | 208 |
formats are: bzip2, gzip and xz. |
| 205 | 209 |
|
| 206 | 210 |
### Usage of .dockerignore |
| 207 | 211 |
|
| 208 |
- $ docker build . |
|
| 209 |
- Uploading context 18.829 MB |
|
| 210 |
- Uploading context |
|
| 211 |
- Step 1 : FROM busybox |
|
| 212 |
- ---> 769b9341d937 |
|
| 213 |
- Step 2 : CMD echo Hello world |
|
| 214 |
- ---> Using cache |
|
| 215 |
- ---> 99cc1ad10469 |
|
| 216 |
- Successfully built 99cc1ad10469 |
|
| 217 |
- $ echo ".git" > .dockerignore |
|
| 218 |
- $ docker build . |
|
| 219 |
- Uploading context 6.76 MB |
|
| 220 |
- Uploading context |
|
| 221 |
- Step 1 : FROM busybox |
|
| 222 |
- ---> 769b9341d937 |
|
| 223 |
- Step 2 : CMD echo Hello world |
|
| 224 |
- ---> Using cache |
|
| 225 |
- ---> 99cc1ad10469 |
|
| 226 |
- Successfully built 99cc1ad10469 |
|
| 212 |
+```bash |
|
| 213 |
+$ docker build . |
|
| 214 |
+ |
|
| 215 |
+Uploading context 18.829 MB |
|
| 216 |
+Uploading context |
|
| 217 |
+Step 1 : FROM busybox |
|
| 218 |
+ ---> 769b9341d937 |
|
| 219 |
+Step 2 : CMD echo Hello world |
|
| 220 |
+ ---> Using cache |
|
| 221 |
+ ---> 99cc1ad10469 |
|
| 222 |
+Successfully built 99cc1ad10469 |
|
| 223 |
+$ echo ".git" > .dockerignore |
|
| 224 |
+$ docker build . |
|
| 225 |
+Uploading context 6.76 MB |
|
| 226 |
+Uploading context |
|
| 227 |
+Step 1 : FROM busybox |
|
| 228 |
+ ---> 769b9341d937 |
|
| 229 |
+Step 2 : CMD echo Hello world |
|
| 230 |
+ ---> Using cache |
|
| 231 |
+ ---> 99cc1ad10469 |
|
| 232 |
+Successfully built 99cc1ad10469 |
|
| 233 |
+``` |
|
| 227 | 234 |
|
| 228 | 235 |
This example shows the use of the `.dockerignore` file to exclude the `.git` |
| 229 | 236 |
directory from the context. Its effect can be seen in the changed size of the |
| ... | ... |
@@ -232,7 +253,9 @@ uploaded context. The builder reference contains detailed information on |
| 232 | 232 |
|
| 233 | 233 |
### Tag image (-t) |
| 234 | 234 |
|
| 235 |
- $ docker build -t vieux/apache:2.0 . |
|
| 235 |
+```bash |
|
| 236 |
+$ docker build -t vieux/apache:2.0 . |
|
| 237 |
+``` |
|
| 236 | 238 |
|
| 237 | 239 |
This will build like the previous example, but it will then tag the resulting |
| 238 | 240 |
image. The repository name will be `vieux/apache` and the tag will be `2.0`. |
| ... | ... |
@@ -244,25 +267,32 @@ version. |
| 244 | 244 |
For example, to tag an image both as `whenry/fedora-jboss:latest` and |
| 245 | 245 |
`whenry/fedora-jboss:v2.1`, use the following: |
| 246 | 246 |
|
| 247 |
- $ docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 . |
|
| 248 |
- |
|
| 247 |
+```bash |
|
| 248 |
+$ docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 . |
|
| 249 |
+``` |
|
| 249 | 250 |
### Specify Dockerfile (-f) |
| 250 | 251 |
|
| 251 |
- $ docker build -f Dockerfile.debug . |
|
| 252 |
+```bash |
|
| 253 |
+$ docker build -f Dockerfile.debug . |
|
| 254 |
+``` |
|
| 252 | 255 |
|
| 253 | 256 |
This will use a file called `Dockerfile.debug` for the build instructions |
| 254 | 257 |
instead of `Dockerfile`. |
| 255 | 258 |
|
| 256 |
- $ docker build -f dockerfiles/Dockerfile.debug -t myapp_debug . |
|
| 257 |
- $ docker build -f dockerfiles/Dockerfile.prod -t myapp_prod . |
|
| 259 |
+```bash |
|
| 260 |
+$ docker build -f dockerfiles/Dockerfile.debug -t myapp_debug . |
|
| 261 |
+$ docker build -f dockerfiles/Dockerfile.prod -t myapp_prod . |
|
| 262 |
+``` |
|
| 258 | 263 |
|
| 259 | 264 |
The above commands will build the current build context (as specified by the |
| 260 | 265 |
`.`) twice, once using a debug version of a `Dockerfile` and once using a |
| 261 | 266 |
production version. |
| 262 | 267 |
|
| 263 |
- $ cd /home/me/myapp/some/dir/really/deep |
|
| 264 |
- $ docker build -f /home/me/myapp/dockerfiles/debug /home/me/myapp |
|
| 265 |
- $ docker build -f ../../../../dockerfiles/debug /home/me/myapp |
|
| 268 |
+```bash |
|
| 269 |
+$ cd /home/me/myapp/some/dir/really/deep |
|
| 270 |
+$ docker build -f /home/me/myapp/dockerfiles/debug /home/me/myapp |
|
| 271 |
+$ docker build -f ../../../../dockerfiles/debug /home/me/myapp |
|
| 272 |
+``` |
|
| 266 | 273 |
|
| 267 | 274 |
These two `docker build` commands do the exact same thing. They both use the |
| 268 | 275 |
contents of the `debug` file instead of looking for a `Dockerfile` and will use |
| ... | ... |
@@ -302,7 +332,9 @@ A good example is `http_proxy` or source versions for pulling intermediate |
| 302 | 302 |
files. The `ARG` instruction lets Dockerfile authors define values that users |
| 303 | 303 |
can set at build-time using the `--build-arg` flag: |
| 304 | 304 |
|
| 305 |
- $ docker build --build-arg HTTP_PROXY=http://10.20.30.2:1234 . |
|
| 305 |
+```bash |
|
| 306 |
+$ docker build --build-arg HTTP_PROXY=http://10.20.30.2:1234 . |
|
| 307 |
+``` |
|
| 306 | 308 |
|
| 307 | 309 |
This flag allows you to pass the build-time variables that are |
| 308 | 310 |
accessed like regular environment variables in the `RUN` instruction of the |
| ... | ... |
@@ -327,6 +359,6 @@ Linux namespaces. On Microsoft Windows, you can specify these values: |
| 327 | 327 |
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 328 | 328 |
| `default` | Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value. | |
| 329 | 329 |
| `process` | Namespace isolation only. | |
| 330 |
-| `hyperv` | Hyper-V hypervisor partition-based isolation. | |
|
| 330 |
+| `hyperv` | Hyper-V hypervisor partition-based isolation. | |
|
| 331 | 331 |
|
| 332 | 332 |
Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`. |