moby: False positive "Empty continuation lines will become errors in a future release."

I have read https://github.com/moby/moby/issues/29005 but I don’t think this was implemented according to what was discussed there.

Description

I’m getting a false positive claiming “Empty continuation lines” however I have no lines which are empty and continued as far as I can tell. I do have a comment inside a command which was previously dropped during parsing but now emits a warning. Docker imo has better comment capabilities for long commands which are continued than the equivalent in bash / sh which is one thing I’ll miss if this deprecation warning becomes an error.

Steps to reproduce the issue:

(this is a MCVE, my actual example is more involved and involves documenting a strange package in an apt line)

FROM ubuntu:xenial
RUN echo \
        # descriptive comment
        hello

docker build .

Describe the results you received:

$ docker build .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM ubuntu:xenial
 ---> 747cb2d60bbe
Step 2/2 : RUN echo         hello
 ---> Running in 42350fdc3408
hello
 ---> 312472115b43
Removing intermediate container 42350fdc3408
[WARNING]: Empty continuation line found in:
    RUN echo         hello
[WARNING]: Empty continuation lines will become errors in a future release.

Describe the results you expected:

(no warning)

$ docker build .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM ubuntu:xenial
 ---> 747cb2d60bbe
Step 2/2 : RUN echo         hello
 ---> Running in 42350fdc3408
hello
 ---> 312472115b43
Removing intermediate container 42350fdc3408

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

$ docker version
Client:
 Version:      17.09.0-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:42:18 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.09.0-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:40:56 2017
 OS/Arch:      linux/amd64
 Experimental: false

Output of docker info:

Containers: 8
 Running: 0
 Paused: 0
 Stopped: 8
Images: 15
Server Version: 17.09.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.10.0-38-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 7.795GiB
Name: asottile-VirtualBox
ID: MCDD:BXAL:Y4PM:SIA7:I73R:W3F6:C4IY:ZEP4:K44W:XLYA:USI2:FAMT
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support

Additional environment details (AWS, VirtualBox, physical, etc.):

I’m on virtualbox, though I doubt it matters

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for your examples; looking at those, that’s actually the intended behavior, because there are empty lines in the RUN;

# install globally popular PHP dev tools
RUN \
    # install Composer globally
    curl -LsS https://getcomposer.org/composer.phar -o ${BIN_PATH}composer \
    && chmod a+x ${BIN_PATH}composer \

    # install CodeCeption globally

The correct approach for that would be to add a continuation marker (\) on the empty lines, for example;

# install globally popular PHP dev tools
RUN \
    # install Composer globally
    curl -LsS https://getcomposer.org/composer.phar -o ${BIN_PATH}composer \
    && chmod a+x ${BIN_PATH}composer \
    \
    # install CodeCeption globally

I attempted to describe why these empty lines can become problematic in https://github.com/moby/moby/issues/29005#issuecomment-264166814

Take this Dockerfile:

FROM busybox
RUN \
  # install foo
  echo "install foo"; \
 

  # steps below are to install the bar package

  # we install the bar backage
  # because installing foo
  # also installs qux

  # and some more comments here
  echo "install bar"


# Do something else
RUN echo "something else"

# And do more things
RUN echo "do more things"

Building that Dockerfile will show the warning, but “install” foo and bar:

Sending build context to Docker daemon  2.048kB
[WARNING]: Empty continuation line found in:
    RUN   echo "install foo"   && echo "install bar"
[WARNING]: Empty continuation lines will become errors in a future release.
Step 1/4 : FROM busybox
 ---> 5b0d59026729
Step 2/4 : RUN   echo "install foo"   && echo "install bar"
 ---> Running in 3bf4182f48de
install foo
install bar
Removing intermediate container 3bf4182f48de
 ---> 19f43b9660db
Step 3/4 : RUN echo "something else"
 ---> Running in ebffefc45f7e
something else
Removing intermediate container ebffefc45f7e
 ---> abe0b719878a
Step 4/4 : RUN echo "do more things"
 ---> Running in 54aad909a779
do more things
Removing intermediate container 54aad909a779
 ---> 47e96daec8fe
Successfully built 47e96daec8fe

Now, just commenting the install bar line:

FROM busybox
RUN \
  # install foo
  echo "install foo" \
 
  # steps below are to install the bar package

  # we install the bar backage
  # because installing foo
  # also installs qux

  # and some more comments here
#  && echo "install bar"


# Do something else
RUN echo "something else"

# And do more things
RUN echo "do more things"

And this will happen:

Sending build context to Docker daemon  2.048kB
[WARNING]: Empty continuation line found in:
    RUN   echo "install foo" RUN echo "something else"
[WARNING]: Empty continuation lines will become errors in a future release.
Step 1/3 : FROM busybox
 ---> 5b0d59026729
Step 2/3 : RUN   echo "install foo" RUN echo "something else"
 ---> Running in 9fdbe730a1e6
install foo RUN echo something else
Removing intermediate container 9fdbe730a1e6
 ---> 523b99f4743c
Step 3/3 : RUN echo "do more things"
 ---> Running in 25ab4df25fbd
do more things
Removing intermediate container 25ab4df25fbd
 ---> 050e028e7473
Successfully built 050e028e7473

The RUN echo "something else" step is now seen as part of the previous RUN

@JoranDox I can see that being convenient for some cases; however, making that change would break thousands of existing Dockerfiles. Implementing https://github.com/moby/moby/issues/34423 would probably be a more convenient approach for that use-case.

@thaJeztah

Why not just treat an empty continuation line as the last line? this would avoid confusing diffs when changing this:

RUN install foo \
 && install bar \
 && install baz

to

RUN install foo \
 && install bar

which would give an unnecessary change on the line for bar.

I’d much rather just have

RUN install foo \
 && install bar \
 && install baz \

RUN other stuff

so I can just delete (or even comment out) lines that are not needed on the fly:

RUN install foo \
 && install bar \

RUN other stuff

(basically this: https://stackoverflow.com/questions/11597901/why-are-trailing-commas-allowed-in-a-list , but instead of python & comma, docker & backslash.)

@boywijnmaalen no worries; it tripped me as well a couple of times 😂