dockerfilelint icon indicating copy to clipboard operation
dockerfilelint copied to clipboard

Should linter raise error if no file found?

Open prog1dev opened this issue 8 years ago • 2 comments

If I run linter with filename which does not exist it just gives me normal output with 4 issues.

Command:

dockerfilelint NotExistingDockerfile

Output:

File:   <contents>
Issues: 4

Line 1: NotExistingDockerfile
Issue  Category      Title                 Description
    1  Possible Bug  Missing Required      All commands in a Dockerfile require at least 1 argument.
                     Arguments             A line in a Dockerfile can be in any of the following formats:
                                           * * *
                                           #### `# Comment`
                                           Docker will treat any line that begins with a `#` as a comment.
                                           * * *
                                           #### `INSTRUCTION arguments`
                                           All instructions require at least 1 argument, and should be on the
                                           same line as the `INSTRUCTION`.
                                           * * *
                                           #### `RUN` continuation
                                           If a `RUN` line ends with a `\`, the next line will be treated as
                                           part of the same `RUN` arguement.
                                           * * *
                                           #### Blank or Whitespace
                                           Blank lines are allowed and will be ignored.
                                           * * *
    2  Clarity       Capitalize            For clarity and readability, all instructions in a Dockerfile
                     Dockerfile            should be uppercase.
                     Instructions          This is a convention adopted by most of the official images and
                                           greatly improves readability in long Dockerfiles.  For an example
                                           of
                                           why this makes a difference, check out the current [redis
                                           Dockerfile](https://github.com/docker-library/redis/blob/b375650fb6
                                           9b7db819e90c0033433c705b28656e/3.0/Dockerfile)
                                           and you should be able to easily see the instructions used.
    3  Possible Bug  First Command Must    The first instruction in a Dockerfile must specify the base image
                     Be FROM               using a FROM command.  Additionally, FROM cannot appear later in a
                                           Dockerfile.
    4  Possible Bug  Invalid Line          This line is not a valid Dockerfile line.

Should linter report internal errors such as it is to stderr? Something like File NotExistingDockerfile not found

prog1dev avatar Nov 11 '17 20:11 prog1dev

@prog1dev I have just come across this issue too and its confusing. Really there should be a more accurate error message about the file not been found.

TheYorkshireDev avatar Dec 03 '17 17:12 TheYorkshireDev

This is because dockerfilelint is interpreting the non-existent-file argument (NotExistingDockerfile in the example above) as the "contents to lint" (i.e. as if the argument is a string containing contents from a Dockerfile). It will do this for each argument that it cannot find on the file system.

Perhaps it shouldn't do this (or shouldn't do this by default)? Would it be better/less confusing to make this behavior opt-in via a CLI flag like --contents or --no-file?

nexdrew avatar Dec 04 '17 15:12 nexdrew