Comments (2)
How does this work in practice?
Do I currently need to run
docker-compose build --no-cache
Every time i update the frontend and backend to get the updates working?
If it is being run locally, use the local build which should support hot-reload and link to local files
is it ./frontend/Dockerfile you are talking about in this quote? I can't see that it has npm install && npm run dev capabilities
from full-stack-fastapi-mongodb.
I have updated ./frontend/Dockerfile to accept npm run dev
It currently works okay. You'll need to run a docker-compose down
then a docker-compose up --build
After this it can be ran normally like docker-compose up -d
I've had some issue where the first time after docker-compose up -d it doesn't really update, but after a refresh it seems to working OK
The ./frontend/Dockerfile should look like this:
# Base stage with Node.js on Alpine Linux
FROM node:18-alpine AS base
WORKDIR /frontend
# Dependency installation stage
FROM base AS deps
# Install necessary system libraries
RUN apk add --no-cache libc6-compat
# Set the working directory
WORKDIR /frontend
# Copy package management files into the image
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
# Install dependencies based on the detected lock file
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else npm install && npm ci; \
fi
# Build stage for production
FROM base AS builder
WORKDIR /frontend
# Copy installed node_modules from deps stage and all source files
COPY --from=deps /frontend/node_modules ./node_modules
COPY . .
# Disable telemetry for production builds
ENV NEXT_TELEMETRY_DISABLED 1
RUN npm run build
# Production stage setup
FROM base AS runner
WORKDIR /frontend
ENV NODE_ENV production
# Further disable telemetry
ENV NEXT_TELEMETRY_DISABLED 1
# Add a system group and user for running the application
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy public assets and the built application from the builder stage
COPY --from=builder /frontend/public ./public
RUN mkdir .next
RUN chown nextjs:nodejs .next
COPY --from=builder --chown=nextjs:nodejs /frontend/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /frontend/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
CMD ["node", "server.js"]
# Development stage setup
FROM base AS development
WORKDIR /frontend
COPY --from=deps /frontend/node_modules ./node_modules
COPY . .
ENV NODE_ENV=development
EXPOSE 3000
CMD ["npm", "run", "dev"]
And then update ./docker-compose.override.yml like so:
...
frontend:
ports:
- "3000:3000"
build:
context: ./frontend
target: development
volumes:
- ./frontend:/frontend # Mount the source code directory to enable hot reloading
- /frontend/node_modules # Use a volume to persist installed node_modules
environment:
- NODE_ENV=development
labels:
- traefik.enable=true
- traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=PathPrefix(`/`)
- traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
...
from full-stack-fastapi-mongodb.
Related Issues (14)
- "Phantom Login" On generated app with magic link sign up HOT 1
- Models are out of date with the new pydantic modeling paradigm from pydantic 2.0 HOT 2
- Should make use of SecretStr for any Token or Password fields HOT 3
- useSearchParams() should be wrapped in a suspense boundary HOT 2
- celeryworker.dockerfile exiting with code: 1 HOT 7
- Unused AgnosticDatabase in Method Signatures HOT 1
- pydantic.errors.PydanticUserError HOT 6
- Possible error in the code base HOT 4
- Example stack: unable to login with "[email protected]"and changethis pwd HOT 4
- TypeError: CRUDUser.is_active() missing 1 required positional argument: 'user' HOT 1
- backend exits "TypeError: type 'types.UnionType' is not subscriptable" HOT 1
- Recommended way to run the docker-compose HOT 1
- (frontend) npm audit 12 vulnerabilities (4 moderate, 7 high, 1 critical) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from full-stack-fastapi-mongodb.