Vscode-docker: add support for multi stage docker files

Created on 28 Apr 2017  ·  7Comments  ·  Source: microsoft/vscode-docker

probably just need to update the default dockerfile template.

https://codefresh.io/blog/node_docker_multistage/

//cc: @lostintangent

rough idea...

FROM node:latest AS base
WORKDIR /usr/src/app
COPY package.json .

FROM base AS dependencies
RUN npm set progress=false && npm config set depth 0
RUN npm install --only=production
RUN cp -R node_modules prod_node_modules
RUN npm install

FROM dependencies AS build
COPY . .
RUN ./node_modules/.bin/gulp
RUN cp -R client prod_client

FROM base AS release
COPY --from=dependencies /usr/src/app/prod_node_modules ./node_modules
COPY --from=build /usr/src/app/prod_client ./client
COPY . .
EXPOSE 3000
CMD npm run start
enhancement needs more info

Most helpful comment

Sounds good! We should also do the following as well:

  1. Update the in-box Docker syntax file to properly colorize the new AS keyword and --from flag. This is lower pri, but would be nice to do, since multi-stage builds are likely to become pretty common

  2. Update the linter rules to not complain about the AS foo clause of the FROM directive. Currently, we give false negatives about this, which isn't ideal

All 7 comments

Sounds good! We should also do the following as well:

  1. Update the in-box Docker syntax file to properly colorize the new AS keyword and --from flag. This is lower pri, but would be nice to do, since multi-stage builds are likely to become pretty common

  2. Update the linter rules to not complain about the AS foo clause of the FROM directive. Currently, we give false negatives about this, which isn't ideal

We should also consider the following enhancements:

  1. Update the hover provider to parse out the image name correctly when using an AS clause in the FROM directive. Right now, the hover behavior is broken when using FROM/AS

  2. Update the Dockerfile completion provider by displaying a completion list of base image names when typing "--from=" in the COPY directive, and the FROM directive

While you are at it. The warning (green squiggle) there can only be one CMD instruction in a Dockerfile is now wrong.

Hi, @seank-com. I believe the bug you are describing is rcjsuen/dockerfile-utils#22. Please see https://github.com/rcjsuen/dockerfile-utils/issues/22#issuecomment-366485869 for a workaround. That bug should hopefully be fixed with the next release of the extension as #249 has been merged in.

Should you spot any other strange or incorrect validation errors, please do not hesitate to let me know. Thanks!

Current Node.js template:

FROM node:10.13-alpine
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json", "npm-shrinkwrap.json", "./"]
RUN npm install --production --silent && mv node_modules ../
COPY . .
EXPOSE 3000
CMD npm start

@lostintangent, @chrisdias Do we need to improve this for better practice?

@lostintangent @chrisdias your thoughts?

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yusufkaratoprak picture yusufkaratoprak  ·  4Comments

Szauka picture Szauka  ·  6Comments

sajayantony picture sajayantony  ·  6Comments

afaddoul picture afaddoul  ·  7Comments

bradygmsft picture bradygmsft  ·  7Comments