microsoft / vscode-docker

Docker Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker
Other
1.18k stars 508 forks source link

Dockerfile Linter doesn't recognize directory destination in COPY command #4292

Open SetTrend opened 2 months ago

SetTrend commented 2 months ago

Synopsis

Although I correctly added a backslash to the destination of my COPY commands, the Dockerfile linter throws an error claiming that I didn't:

Dockerfile linter error

Current Situation

The Dockerfile linter erroneously throws an error about a missing a trailing backslash although it has been provided.

Desired Situation

  1. A trailing backslash should only be required for the destination path if the source is not a single file. (For paths containing spaces, the array syntax is mandatory.)
  2. A trailing backslash in the destination path portion of the command should correctly be recognized.
  3. The use of variables (ARG, ENV variables) should be correctly parsed and interpreted.

VS Code Docker Extension Version

v1.29.0



Dockerfile Example Using Variables

The same Dockerfile as above, this time using variables for destination:

Dockerfile example using variables

rcjsuen commented 2 months ago

For the backslash case, it's the challenge of interpreting quotes. As a workaround, if you put double backslashes the issue should go away.

SetTrend commented 2 months ago

I'm not confident that your statement is correct.

In the first line of the Dockerfile there is a parser directive # escape=`. The Dockerfile reference claims that when using this directive, you don't need to escape backslashes.

rcjsuen commented 2 months ago

I'm not confident that your statement is correct.

In the first line of the Dockerfile there is a parser directive # escape=`. The Dockerfile reference claims that when using this directive, you don't need to escape backslashes.

@SetTrend Thank you for pointing that out. You are correct that it does seem that the parser directive is not just for newlines at the end of a line in the file but also for content within the line. Sorry about that.

The escape character is used both to escape characters in a line, and to escape a newline.

SetTrend commented 2 months ago

Perhaps you may want to follow this discussion on the Dockerfile COPY syntax first before beginning to solve this issue:

/docker/docs/issues/19922: Dockerfile COPY instruction description is misleading

rcjsuen commented 2 months ago

Perhaps you may want to follow this discussion on the Dockerfile COPY syntax first before beginning to solve this issue:

/docker/docs/issues/19922: Dockerfile COPY instruction description is misleading

Thanks for the pointer. This does sound vaguely familiar...