Help understanding comment issues at line 1 in Dockerfile
AmauryOrtega opened this issue Β· comments
I'm using the latest docker image replicated/dockerfilelint:latest
to test my Dockerfile and I'm getting this output (First try). I do not understand which comment is raising this issue. I thought it was the comments on line 3 and 4 so I removed then and tried again but no luck (Second try).
Can someone explain to me what is happening here?
First try
Dockerfile
FROM node:12-alpine
# Use latest stable npm
# RUN npm install -g npm@latest
# Install:
# hadolint ignore=DL3016,DL3018
RUN npm install --no-optional --quiet --yes -g \
pm2 \
&& apk --no-cache add curl \
&& rm -rf /var/cache/apk/*
# Source directory
ENV APP_DIR=/usr/src/app/
RUN mkdir -p ${APP_DIR} && chown -R node:node ${APP_DIR}
WORKDIR ${APP_DIR}
# Dropping privileges
USER node
# Install dependencies
# CI=True, Disables progress bars https://docs.npmjs.com/misc/config#progress
ENV CI=true
COPY --chown=node:node package* ./
RUN npm ci --no-optional --quiet --yes && npm prune --production
# Code
COPY --chown=node:node . .
USER root
# Entrypoint and wait script
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /bin/wait
COPY docker-entrypoint.sh /bin/docker-entrypoint.sh
RUN chmod +x /bin/wait /bin/docker-entrypoint.sh
ENTRYPOINT [ "/bin/docker-entrypoint.sh" ]
# Default execution
EXPOSE 8080
ENV HOST=0.0.0.0 PORT=8080 NODE_ENV=production
# HEALTHCHECK CMD curl -f http://localhost:"$PORT"/healthcheck || exit 1
USER node
# Run pm2 on foreground
CMD ["pm2-runtime", "start", "ecosystem.config.js"]
Output
$ docker run --rm -v "$PWD"/Dockerfile:/Dockerfile replicated/dockerfilelint:latest Dockerfile
File: <contents>
Issues: 4
Line 1: Dockerfile
Issue Category Title Description
1 Possible Bug Missing Required All commands in a Dockerfile require at least 1 argument.
Arguments A line in a Dockerfile can be in any of the following formats:
* * *
#### `# Comment`
Docker will treat any line that begins with a `#` as a comment.
* * *
#### `INSTRUCTION arguments`
All instructions require at least 1 argument, and should be on the
same line as the `INSTRUCTION`.
* * *
#### `RUN` continuation
If a `RUN` line ends with a `\`, the next line will be treated as
part of the same `RUN` arguement.
* * *
#### Blank or Whitespace
Blank lines are allowed and will be ignored.
* * *
2 Clarity Capitalize For clarity and readability, all instructions in a Dockerfile
Dockerfile should be uppercase.
Instructions This is a convention adopted by most of the official images and
greatly improves readability in long Dockerfiles. For an example
of
why this makes a difference, check out the current [redis
Dockerfile](https://github.com/docker-library/redis/blob/b375650fb6
9b7db819e90c0033433c705b28656e/3.0/Dockerfile)
and you should be able to easily see the instructions used.
3 Possible Bug First Command Must The first instruction in a Dockerfile must specify the base image
Be FROM or ARG using a FROM command or an ARG command to modify the FROM command.
Additionally, FROM cannot appear later in a Dockerfile.
4 Possible Bug Invalid Line This line is not a valid Dockerfile line.
First try
Dockerfile
FROM node:12-alpine
# Install:
# hadolint ignore=DL3016,DL3018
RUN npm install --no-optional --quiet --yes -g \
pm2 \
&& apk --no-cache add curl \
&& rm -rf /var/cache/apk/*
# Source directory
ENV APP_DIR=/usr/src/app/
RUN mkdir -p ${APP_DIR} && chown -R node:node ${APP_DIR}
WORKDIR ${APP_DIR}
# Dropping privileges
USER node
# Install dependencies
# CI=True, Disables progress bars https://docs.npmjs.com/misc/config#progress
ENV CI=true
COPY --chown=node:node package* ./
RUN npm ci --no-optional --quiet --yes && npm prune --production
# Code
COPY --chown=node:node . .
USER root
# Entrypoint and wait script
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /bin/wait
COPY docker-entrypoint.sh /bin/docker-entrypoint.sh
RUN chmod +x /bin/wait /bin/docker-entrypoint.sh
ENTRYPOINT [ "/bin/docker-entrypoint.sh" ]
# Default execution
EXPOSE 8080
ENV HOST=0.0.0.0 PORT=8080 NODE_ENV=production
# HEALTHCHECK CMD curl -f http://localhost:"$PORT"/healthcheck || exit 1
USER node
# Run pm2 on foreground
CMD ["pm2-runtime", "start", "ecosystem.config.js"]
Output
$ docker run --rm -v "$PWD"/Dockerfile:/Dockerfile replicated/dockerfilelint:latest Dockerfile
File: <contents>
Issues: 4
Line 1: Dockerfile
Issue Category Title Description
1 Possible Bug Missing Required All commands in a Dockerfile require at least 1 argument.
Arguments A line in a Dockerfile can be in any of the following formats:
* * *
#### `# Comment`
Docker will treat any line that begins with a `#` as a comment.
* * *
#### `INSTRUCTION arguments`
All instructions require at least 1 argument, and should be on the
same line as the `INSTRUCTION`.
* * *
#### `RUN` continuation
If a `RUN` line ends with a `\`, the next line will be treated as
part of the same `RUN` arguement.
* * *
#### Blank or Whitespace
Blank lines are allowed and will be ignored.
* * *
2 Clarity Capitalize For clarity and readability, all instructions in a Dockerfile
Dockerfile should be uppercase.
Instructions This is a convention adopted by most of the official images and
greatly improves readability in long Dockerfiles. For an example
of
why this makes a difference, check out the current [redis
Dockerfile](https://github.com/docker-library/redis/blob/b375650fb6
9b7db819e90c0033433c705b28656e/3.0/Dockerfile)
and you should be able to easily see the instructions used.
3 Possible Bug First Command Must The first instruction in a Dockerfile must specify the base image
Be FROM or ARG using a FROM command or an ARG command to modify the FROM command.
Additionally, FROM cannot appear later in a Dockerfile.
4 Possible Bug Invalid Line This line is not a valid Dockerfile line.
@AmauryOrtega I've copied the Dockerfile locally and tried it here, and it reports
Issues: None found π
Could you share some details of the command line you are using to execute the linting?
@marccampbell Thanks for your help, the command line I used is in the output section on my previous comment.
Because it's been a while I didn't focus on this, I was able to come back with a clear mind and I just now realized that it was my mistake.
The replicated/dockerfilelint's dockerfile clearly states that the workdir is set to /dockerfilelint
I assumed the workdir was /
so I placed the Dockerfile in /Dockerfile
and tried calling it. That's why the tool was outputting File: <contents>
.
I changed my command to
$ docker run --rm -v "$PWD"/Dockerfile:/dockerfilelint/Dockerfile replicated/dockerfilelint:latest Dockerfile
File: Dockerfile
Issues: None found π
It also would've worked if I just followed the README.md as intended.