Reputation: 1637
Most of the DockerFiles seem to be generating the image from the source code directory. Is there a reason why this is done?
For example, If I run the build commands in a windows machine and copy the dist folder into a linux machine and run as per Option 2, isn't it supposed to work?
Option 1 - Docker file (from source directory)
FROM node:latest as build
WORKDIR /usr/local/app
COPY ./ /usr/local/app/
RUN npm install
RUN npm run build
FROM nginx:latest
COPY --from=build /usr/local/app/dist /usr/share/nginx/html
EXPOSE 80
Option 2 - Dockerfile from build output
FROM nginx:latest
COPY dist /usr/share/nginx/html
EXPOSE 80
Upvotes: 0
Views: 1029
Reputation: 159830
Your first form uses a Docker multi-stage build. This has the specific advantage of not depending on any particular tools being installed on the host system. I'd consider this path:
The second path depends on having the toolchain available outside the container environment. That's not necessarily a problem; most front-end developers will probably have Node installed anyways. I'd consider this path:
.jar
files; interpreted text-format Python or Ruby scripting code).For what you show, with a simple front-end application that's compiled to static files, your second form is just fine. If you look at SO Java questions they almost universally COPY
a prebuilt .jar
file into an image, without including a build chain.
Upvotes: 1