Update multistage example

This commit is contained in:
Mike Conrad
2025-06-08 11:50:05 -04:00
parent 77a19aabda
commit 38375961b0

View File

@ -236,28 +236,32 @@ layout: center
## Multi Stage builds ## Multi Stage builds
```dockerfile ```dockerfile
# Stage 1: Build the Go binary # Stage 1 - Define Base image
FROM node:22-alpine AS base FROM node:22-alpine AS base
FROM base AS build # Stage 2 Install dependencies
# Set working directory inside the build container FROM base AS install-deps
WORKDIR /app WORKDIR /app
COPY package*.json ./ COPY package*.json /app/
RUN yarn RUN yarn
# Stage 3 Development
FROM base AS develop FROM install-deps AS develop
COPY --from=base /app/node_modules /app/node_modules WORKDIR /app
COPY --from=install-deps /app/node_modules /app/node_modules
COPY . . COPY . .
ENTRYPOINT ["yarn", "dev", "--host=0.0.0.0"]
ENTRYPOINT ["yarn", "dev"] EXPOSE 5173
EXPOSE 3000
``` ```
- Use specific versions, not `latest` ```bash
- Combine commands to reduce layers $ docker build -t react .
- Use `.dockerignore` $ docker run --rm -P react
- Prefer slim or alpine images ```
- Run as non-root user if possible <!--
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 transition: fade-out
layout: center layout: center