44

Consider the following Dockerfile:

FROM alpine:edge

EXPOSE \
# web portal
8080 \
# backdoor
8081

Built like so:

docker build .

We observe such output:

Sending build context to Docker daemon  17.1TB
Step 1/2 : FROM alpine:edge
 ---> 7463224280b0
Step 2/2 : EXPOSE 8080 8081
 ---> Using cache
 ---> 7953f8df04d9
[WARNING]: Empty continuation line found in:
    EXPOSE 8080 8081
[WARNING]: Empty continuation lines will become errors in a future release.
Successfully built 7953f8df04d9

So, given that it'll soon become illegal to put comments in the middle of a multi-line section: what's the new recommended way to comment multi-line commands?

This is particularly important for RUN commands, since we are encouraged to reduce image layers by &&ing commands together.


Not sure exactly when this was introduced, but I'm currently experiencing this in version:

 docker --version
Docker version 17.07.0-ce, build 8784753

I'm using Docker's edge release stream, so maybe this will not yet look familiar if you are using Docker stable.

Birchlabs
  • 7,437
  • 5
  • 35
  • 54

4 Answers4

22

17.07.0-ce started to warn on empty continuation lines. However, it incorrectly treated comment-only lines as empty. This is fixed in moby#35004, and being included in the 17.10.0-ce.

Tanner Sansbury
  • 51,153
  • 9
  • 112
  • 169
20

On top of what others have said above (the error might be related to comments inside continuation blocks and/or windows cr/lf characters = use dos2unix), this message can also show up when your last command ends with a backslash \ character. For example, if you have this:

RUN apt-get update \
    && apt-get upgrade \
    && apt-get -y install build-essential curl gnupg libfontconfig ca-certificates bzip2 \
    && curl -sL https://deb.nodesource.com/setup_16.x  | bash - \
    && apt-get -y install nodejs \
    && apt-get clean \
    && rm -rf /tmp/* /var/lib/apt/lists/* \

Notice the last \ at the end. This will get you the same error:

docker [WARNING]: Empty continuation line found in:

So, just remove that last \ and you're all set.

Pierre
  • 2,335
  • 22
  • 40
2

You could break the RUN commands out on to separate lines, and then use the experimental (at time of writing*) --squash command.


* note that it's been suggested that multi-stage builds might make --squash redundant. That is actively being discussed here, with a proposal open here.

davetapley
  • 17,000
  • 12
  • 60
  • 86
  • `--squash` presumably means that _all_ layers get invalidated when I make a change to just the newest layer. generally I put slow stuff in early layers, and volatile stuff in later layers. I'd not like my incremental builds to have to re-fetch dependencies every time, just for the sake of implementing comments. but maybe multi-stage builds provides a better answer; need to read up on it. – Birchlabs Oct 26 '17 at 19:12
2

If, like me, you came here with the same error but no comments in your Dockerfile's RUN item, you have either mixed or DOS line endings. Run dos2unix on your Dockerfile and that'll fix it.

Scott S
  • 341
  • 4
  • 11