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
Next revision
Previous revision
marc:linux:docker [2022/04/18 10:22] – [Docker Compose:] marcvmarc:linux:docker [2022/04/19 10:03] (current) – [2 phase container building:] marcv
Line 248: Line 248:
       - .:/app                                   # copy all from local working directory to app directory inside       - .:/app                                   # copy all from local working directory to app directory inside
                                                  # container (except /app/node_volumes!)                                                  # container (except /app/node_volumes!)
 +    app3:
 +      restart: never
 +      build:
 +        context: .                               # working directory
 +        dockerfile: ./Dockerfile.dev             # define another file than default (Dockerfile)
 +                                                 # it can also be a url to a git_directory
 </code> </code>
  
Line 297: Line 303:
  
 {{:marc:linux:github_workflow.png?direct&800|}} {{:marc:linux:github_workflow.png?direct&800|}}
 +
 +
 +===== 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|}}
 +
 +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.1650270175.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki