GoLand 2021.3 Help

Code Inspections in Dockerfile

This topic lists all GoLand code inspections available in Dockerfile.

You can toggle specific inspections or change their severity level on the Editor | Inspections page of the IDE settings Ctrl+Alt+S.

Inspection

Description

Default Severity

Invalid destination for ''ADD''/''COPY'' commands

Reports invalid destination directories in ADD and COPY commands.

According to the Dockerfile specification, if multiple sources are specified, then the destination must be a directory, and it must end with a slash '/'. Otherwise, Docker build will fail.

Examples:
# all the commands below will fail ADD textA.txt textB.txt relativeDir ADD ["binaryA.jar", "binary2.jar", "destination"] COPY text3.txt text4.txt /absolute/path

After the quick-fix is applied:
ADD textA.txt textB.txt relativeDir/ ADD ["binaryA.jar", "binary2.jar", "destination/"] COPY text3.txt text4.txt /absolute/path/

Warning Warning

Invalid spaces in ''key=value'' pair

Reports incorrect spacing for key-value pairs in ARG, ENV, and LABEL commands.

While it is not explicitly specified in the Dockerfile specification, some combinations of spacing for key-value pairs are not allowed. Docker build will fail after reaching the problem instruction.

Examples:
  • The ARG command does not allow any spaces around '='

  • ENV and LABEL do not allow spaces after '='

# all the commands below will fail ARG answer = 42 ARG version= "1.0.0" LABEL "maintained.by"= someone@gmail.com ENV JAVA_HOME= "/docker-java-home"

After the quick-fix is applied:
ARG answer=2 ARG version="1.0.0" LABEL "maintained.by"=someone@gmail.com ENV JAVA_HOME="/docker-java-home"

Error Error

Missing continuation character for ''RUN'' command

Reports missing continuation characters in RUN command.

In the shell form of RUN command you should use a '\' (backslash) to continue a single RUN instruction onto the next line. Otherwise, Docker build will fail.

Examples:
# the command below will fail RUN /bin/bash -c 'source $HOME/.bashrc; echo $HOME'

After the quick-fix is applied:
RUN /bin/bash -c 'source $HOME/.bashrc; \ echo $HOME'

Error Error

Wrong number of arguments

Reports invalid number of arguments for the Dockerfile commands.

Docker build will fail after reaching the instruction with an invalid number of arguments.

Error Error

Last modified: 11 February 2022