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:03] – [Additional Dockerfile instructions:] marcv | marc:linux:docker [2022/04/19 10:03] (current) – [2 phase container building:] marcv | ||
|---|---|---|---|
| Line 244: | Line 244: | ||
| ports: | ports: | ||
| - " | - " | ||
| + | volumes: | ||
| + | - / | ||
| + | - .:/ | ||
| + | # container (except / | ||
| + | app3: | ||
| + | restart: never | ||
| + | build: | ||
| + | context: . # working directory | ||
| + | dockerfile: ./ | ||
| + | # it can also be a url to a git_directory | ||
| </ | </ | ||
| Line 293: | 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.1650269028.txt.gz · Last modified: (external edit)
