Skip to content

Commit

Permalink
Add CopyIgnoredFile documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Talon Bowler <talon.bowler@docker.com>
  • Loading branch information
daghack committed Jul 9, 2024
1 parent 317c41e commit f5ad057
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
4 changes: 4 additions & 0 deletions frontend/dockerfile/docs/rules/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@ $ docker build --check .
<td><a href="./invalid-default-arg-in-from/">InvalidDefaultArgInFrom</a></td>
<td>Default value for global ARG results in an empty or invalid base image name</td>
</tr>
<tr>
<td><a href="./copy-ignored-file/">CopyIgnoredFile</a></td>
<td>Attempting to Copy file that is excluded by .dockerignore</td>
</tr>
</tbody>
</table>
45 changes: 45 additions & 0 deletions frontend/dockerfile/docs/rules/copy-ignored-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: CopyIgnoredFile
description: Attempting to Copy file that is excluded by .dockerignore
aliases:
- /go/dockerfile/rule/copy-ignored-file/
---

## Output

```text
Attempting to Copy file "./tmp/Dockerfile" that is excluded by .dockerignore
```

## Description

When you use the Add or Copy instructions from within a Dockerfile, you should
ensure that the files to be copied into the image do not match a pattern
present in `.dockerignore`.

Files which match the patterns in a `.dockerignore` file are not present in the
context of the image when it is built. Trying to copy or add a file which is
missing from the context will result in a build error.

## Examples

With the given `.dockerignore` file:

```text
*/tmp/*
```

❌ Bad: Attempting to Copy file "./tmp/Dockerfile" that is excluded by .dockerignore

```dockerfile
FROM scratch
COPY ./tmp/helloworld.txt /helloworld.txt
```

✅ Good: Copying a file which is not excluded by .dockerignore

```dockerfile
FROM scratch
COPY ./forever/helloworld.txt /helloworld.txt
```

37 changes: 37 additions & 0 deletions frontend/dockerfile/linter/docs/CopyIgnoredFile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Output

```text
Attempting to Copy file "./tmp/Dockerfile" that is excluded by .dockerignore
```

## Description

When you use the Add or Copy instructions from within a Dockerfile, you should
ensure that the files to be copied into the image do not match a pattern
present in `.dockerignore`.

Files which match the patterns in a `.dockerignore` file are not present in the
context of the image when it is built. Trying to copy or add a file which is
missing from the context will result in a build error.

## Examples

With the given `.dockerignore` file:

```text
*/tmp/*
```

❌ Bad: Attempting to Copy file "./tmp/Dockerfile" that is excluded by .dockerignore

```dockerfile
FROM scratch
COPY ./tmp/helloworld.txt /helloworld.txt
```

✅ Good: Copying a file which is not excluded by .dockerignore

```dockerfile
FROM scratch
COPY ./forever/helloworld.txt /helloworld.txt
```
2 changes: 1 addition & 1 deletion frontend/dockerfile/linter/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ var (
RuleCopyIgnoredFile = LinterRule[func(string, string) string]{
Name: "CopyIgnoredFile",
Description: "Attempting to Copy file that is excluded by .dockerignore",
URL: "",
URL: "https://docs.docker.com/go/dockerfile/rule/copy-ignored-file/",
Format: func(cmd, file string) string {
return fmt.Sprintf("Attempting to %s file %q that is excluded by .dockerignore", cmd, file)
},
Expand Down

0 comments on commit f5ad057

Please sign in to comment.