Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning at multistage build #100

Closed
AuthorProxy opened this issue Apr 11, 2018 · 6 comments · Fixed by #151
Closed

Warning at multistage build #100

AuthorProxy opened this issue Apr 11, 2018 · 6 comments · Fixed by #151

Comments

@AuthorProxy
Copy link

Gives next warnings dockerfilelint:
15:1 warning dockerfilelint: Clarity Base images should specify a tag to use.
21:1 warning dockerfilelint: Clarity Base images should specify a tag to use.
26:1 warning dockerfilelint: Clarity Base images should specify a tag to use.

Where should I put this tag?

# docker --host=:3000 build -t spa .

# ---- Base image ----
FROM node:alpine AS base

LABEL version="1.0"
LABEL description="HRketing SPA application"
LABEL maintainer="Alex Kostyukov <kostyukov@itopcase.ru>"

RUN apk --no-cache --update add git
WORKDIR /usr/src/deps
COPY package*.json ./

# ---- Dependencies ----
FROM base AS dependencies
RUN npm set progress=false && npm config set depth 0
RUN npm install --loglevel=error --only=production --prefix node_modules_production
RUN npm install --loglevel=error

# ---- Linters ----
FROM dependencies AS test
COPY . .
RUN npm run lint

# ---- Release ----
FROM base AS release

ARG NODE_ENV=production
ENV NODE_ENV=$NODE_ENV

WORKDIR /usr/src/app
COPY --from=dependencies /usr/src/deps/node_modules_production ./node_modules
COPY . .
EXPOSE 3000
CMD ["npm", "run", "deploy"]
@AmauryOrtega
Copy link

@AuthorProxy This warning appears because you don't specify the tag on the FROM statements.
An example for a multistage build that doesn't show those warnings:

FROM node:8.4.0-slim as clientbuilder
WORKDIR /app
COPY src/main/frontend .
RUN yarn
RUN npm run build

FROM openjdk:8u141-jdk-slim as serverbuilder
WORKDIR /app
COPY . .
COPY --from=clientbuilder /app/dist /app/src/main/resources/static
RUN ./gradlew build

FROM openjdk:8-jre-alpine
ENV artifact app-0.0.1.jar
WORKDIR /app
COPY --from=serverbuilder /app/build/libs/${artifact} /app
EXPOSE 8080
ENTRYPOINT ["sh", "-c"]
CMD ["java -jar ${artifact}"]

In this case, the warning that appears are:

  • Line 8: First Command Must Be FROM (Possible Bug)
  • Line 15: First Command Must Be FROM (Possible Bug)

This is expected since there is no multistage support.

@vladkras vladkras mentioned this issue Dec 25, 2018
@darkvertex
Copy link

Found this issue after discovering there's no multistage support.

For anyone that needs such a thing, consider the alternative linter hadolint.

@AmauryOrtega
Copy link

AmauryOrtega commented Sep 6, 2019

@darkvertex Thanks!. The multistage Dockerfile I used as an example before shows no warnings on the online version of hadolint.

@SimonHeimberg
Copy link

SimonHeimberg commented Jun 29, 2020

There are two online checkers using this tool:

But the other problem:
Both ask for a tag for line 15 (FROM base AS dependencies), which does not make sense (at least probably) because base is defined in the dockerfile. This also happens on version 1.5.0 running locally. The alternative hadolint does not have this problem.

@AmauryOrtega
Copy link

@SimonHeimberg I checked the Dockerfile posted by @AuthorProxy and the one I posted as an example in http://www.dockerfilelint.com and noticed that the line FROM base AS dependencies gives a warning because of the FROM <any_image>:<tag> is correctly using the image base but it doesn't have a tag associated to it.

dockerfilelint must be thinking that base is a published image and using the latest tag (assumed because the tag is not present) is not recommended.

The bug could be summarized into: When reusing stages with the FROM directive in a multistage Dockerfile, dockerfilelint gives a false positive warning for not having a tag associated to it.

@Aylr
Copy link

Aylr commented Jul 6, 2020

@AmauryOrtega Thanks for this nice summary. I can confirm your findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants