| 1 |
## Output |
| 2 |
|
| 3 |
```text |
| 4 |
Attempting to Copy file "./tmp/Dockerfile" that is excluded by .dockerignore |
| 5 |
``` |
| 6 |
|
| 7 |
## Description |
| 8 |
|
| 9 |
When you use the Add or Copy instructions from within a Dockerfile, you should |
| 10 |
ensure that the files to be copied into the image do not match a pattern |
| 11 |
present in `.dockerignore`. |
| 12 |
|
| 13 |
Files which match the patterns in a `.dockerignore` file are not present in the |
| 14 |
context of the image when it is built. Trying to copy or add a file which is |
| 15 |
missing from the context will result in a build error. |
| 16 |
|
| 17 |
## Examples |
| 18 |
|
| 19 |
With the given `.dockerignore` file: |
| 20 |
|
| 21 |
```text |
| 22 |
*/tmp/* |
| 23 |
``` |
| 24 |
|
| 25 |
❌ Bad: Attempting to Copy file "./tmp/Dockerfile" that is excluded by .dockerignore |
| 26 |
|
| 27 |
```dockerfile |
| 28 |
FROM scratch |
| 29 |
COPY ./tmp/helloworld.txt /helloworld.txt |
| 30 |
``` |
| 31 |
|
| 32 |
✅ Good: Copying a file which is not excluded by .dockerignore |
| 33 |
|
| 34 |
```dockerfile |
| 35 |
FROM scratch |
| 36 |
COPY ./forever/helloworld.txt /helloworld.txt |
| 37 |
``` |