Add Dockerfile and update README with deployment instructions
This commit is contained in:
parent
3567b9208c
commit
15235cd5f9
52
Dockerfile
Normal file
52
Dockerfile
Normal file
@ -0,0 +1,52 @@
|
||||
# Multi-stage Dockerfile for Next.js Application
|
||||
|
||||
# Build stage
|
||||
FROM node:24-alpine AS builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci --only=production
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the Next.js application
|
||||
RUN npm run build
|
||||
|
||||
# Production stage
|
||||
FROM node:24-alpine AS production
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -g 1001 -S nodejs && \
|
||||
adduser -S nextjs -u 1001
|
||||
|
||||
# Copy dependencies from builder stage
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
|
||||
# Copy source code
|
||||
COPY --from=builder /app/.env ./.env
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
# Change ownership
|
||||
RUN chown -R nextjs:nodejs /app
|
||||
USER nextjs
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost:3000/health || exit 1
|
||||
|
||||
# Start command
|
||||
CMD ["npm", "start"]
|
||||
28
README.md
28
README.md
@ -47,6 +47,34 @@ npm run build
|
||||
|
||||
### Deployment
|
||||
|
||||
#### Docker Deployment
|
||||
|
||||
This project includes a Dockerfile for containerized deployment. To build and run the application using Docker:
|
||||
|
||||
1. Build the image:
|
||||
```bash
|
||||
docker build -t nicholais-website .
|
||||
```
|
||||
|
||||
2. Run the container:
|
||||
```bash
|
||||
docker run -p 3000:3000 nicholais-website
|
||||
```
|
||||
|
||||
3. Or with environment variables:
|
||||
```bash
|
||||
docker run -p 3000:3000 -e NODE_ENV=production nicholais-website
|
||||
```
|
||||
|
||||
#### Environment Variables
|
||||
|
||||
The application supports the following environment variables:
|
||||
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| `NODE_ENV` | Node.js environment | `development` |
|
||||
| `PORT` | Port to run the server on | `3000` |
|
||||
|
||||
## License
|
||||
|
||||
This project is open source, take it. I don't give a fuck. I am not your dad.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user