You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can see many of these practices and recommendations in action in the [buildpack-deps `Dockerfile`](https://github.com/docker-library/buildpack-deps/blob/master/jessie/Dockerfile).
25
-
26
-
> Note: for more detailed explanations of any of the Dockerfile commands
24
+
> **Note**: for more detailed explanations of any of the Dockerfile commands
27
25
>mentioned here, visit the [Dockerfile Reference](../../reference/builder.md) page.
28
26
29
27
## General guidelines and recommendations
@@ -40,12 +38,36 @@ stateless fashion.
40
38
41
39
### Use a .dockerignore file
42
40
43
-
In most cases, it's best to put each Dockerfile in an empty directory. Then,
44
-
add to that directory only the files needed for building the Dockerfile. To
45
-
increase the build's performance, you can exclude files and directories by
46
-
adding a `.dockerignore` file to that directory as well. This file supports
47
-
exclusion patterns similar to `.gitignore` files. For information on creating one,
48
-
see the [.dockerignore file](../../reference/builder.md#dockerignore-file).
41
+
The current working directory where you are located when you issue a
42
+
`docker build` command is called the _build context_, and the `Dockerfile` must
43
+
be somewhere within this build context. By default, it is assumed to be in the
44
+
current directory, but you can specify a different location by using the `-f`
45
+
flag. Regardless of where the `Dockerfile` actually lives, all of the recursive
46
+
contents of files and directories in the current directory are sent to the
47
+
Docker daemon as the _build context_. Inadvertently including files that are not
48
+
necessary for building the image results in a larger build context and larger
49
+
image size. These in turn can increase build time, time to pull and push the
50
+
image, and the runtime size of containers. To see how big your build context
51
+
is, look for a message like the following, when you build your `Dockerfile`.
52
+
53
+
```none
54
+
Sending build context to Docker daemon 187.8MB
55
+
```
56
+
57
+
To exclude files which are not relevant to the build, without restructuring your
58
+
source repisotiry, use a `.dockerignore` file. This file supports
59
+
exclusion patterns similar to `.gitignore` files. For information on creating
60
+
one, see the [.dockerignore file](../../reference/builder.md#dockerignore-file).
61
+
In addition to using a `.dockerignore` file, check out the information below
62
+
on [multi-stage builds](#use-multi-stage-builds).
63
+
64
+
### Use multi-stage builds
65
+
66
+
If you use Docker 17.05 or higher, you can use
67
+
[multi-stage builds](/engine/userguide/eng-image/multistage-build.md) to
68
+
drastically reduce the size of your final image, without the need to
69
+
jump through hoops to reduce the number of intermediate layers or remove
0 commit comments