Update multistage example
This commit is contained in:
36
slides.md
36
slides.md
@ -236,28 +236,32 @@ layout: center
|
||||
## Multi Stage builds
|
||||
|
||||
```dockerfile
|
||||
# Stage 1: Build the Go binary
|
||||
# Stage 1 - Define Base image
|
||||
FROM node:22-alpine AS base
|
||||
FROM base AS build
|
||||
# Set working directory inside the build container
|
||||
# Stage 2 Install dependencies
|
||||
FROM base AS install-deps
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
COPY package*.json /app/
|
||||
RUN yarn
|
||||
|
||||
FROM base AS develop
|
||||
COPY --from=base /app/node_modules /app/node_modules
|
||||
# Stage 3 Development
|
||||
FROM install-deps AS develop
|
||||
WORKDIR /app
|
||||
COPY --from=install-deps /app/node_modules /app/node_modules
|
||||
COPY . .
|
||||
|
||||
ENTRYPOINT ["yarn", "dev"]
|
||||
EXPOSE 3000
|
||||
ENTRYPOINT ["yarn", "dev", "--host=0.0.0.0"]
|
||||
EXPOSE 5173
|
||||
```
|
||||
|
||||
- Use specific versions, not `latest`
|
||||
- Combine commands to reduce layers
|
||||
- Use `.dockerignore`
|
||||
- Prefer slim or alpine images
|
||||
- Run as non-root user if possible
|
||||
|
||||
```bash
|
||||
$ docker build -t react .
|
||||
$ docker run --rm -P react
|
||||
```
|
||||
<!--
|
||||
Run docker image and demonstrate dev container functionality. Attach to the running container
|
||||
via VSCode extension and make changes to code. Note that it updates in real time in the browser.
|
||||
Kill the container and start a new one. Note that the files do not persist. Need volume/bind mounts
|
||||
For that.
|
||||
-->
|
||||
---
|
||||
transition: fade-out
|
||||
layout: center
|
||||
|
Reference in New Issue
Block a user