marc:linux:docker
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| marc:linux:docker [2022/04/18 10:32] – [Docker Compose:] marcv | marc:linux:docker [2022/04/19 10:03] (current) – [2 phase container building:] marcv | ||
|---|---|---|---|
| Line 253: | Line 253: | ||
| context: . # working directory | context: . # working directory | ||
| dockerfile: ./ | dockerfile: ./ | ||
| - | # it can also be a url to a git_directory | + | # it can also be a url to a git_directory |
| </ | </ | ||
| Line 303: | Line 303: | ||
| {{: | {{: | ||
| + | |||
| + | |||
| + | ===== 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 | ||
| + | |||
| + | |||
| + | {{: | ||
| + | |||
| + | The __Dockerfile__ would look something like this: | ||
| + | |||
| + | < | ||
| + | FROM node:alpine as builder | ||
| + | WORKDIR '/ | ||
| + | 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 " | ||
| + | COPY --from=builder /app/build / | ||
| + | </ | ||
| + | |||
| + | Notice we did not define the RUN command; this is not needed as this container will start nginx itself. | ||
marc/linux/docker.1650270766.txt.gz · Last modified: (external edit)
