Site Tools


marc:linux:docker

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
marc:linux:docker [2022/04/19 09:50] – [Github CI/CD:] marcvmarc:linux:docker [2022/04/19 10:03] (current) – [2 phase container building:] marcv
Line 306: Line 306:
  
 ===== 2 phase container building: ===== ===== 2 phase container building: =====
 +
 +By using a multiphase build we can:
 +
 +  - Use multiple images
 +  - Reduce space by only copying the needed contents to the final container
 +
  
 {{:marc:linux:multi_phase_build.png?direct&800|}} {{:marc:linux:multi_phase_build.png?direct&800|}}
 +
 +The __Dockerfile__ would look something like this:
 +
 +<code>
 +FROM node:alpine as builder        # Using "as" we can tag this phase
 +WORKDIR '/app'
 +COPY package.json .
 +RUN npm install
 +COPY . .
 +RUN npm run build                  # This creates the content we want to serve in the /app/build directory
 +
 +FROM nginx                         # Not using another tag; we differentiate the phases using "FROM"
 +COPY --from=builder /app/build /usr/share/nginx/html
 +</code>
 +
 +Notice we did not define the RUN command; this is not needed as this container will start nginx itself.
marc/linux/docker.1650354642.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki