"Empty Continuation Lines Will Become Errors"… How Should I Comment My Dockerfile Now?

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.

2

4 Answers

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.

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   | 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.

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest