Skip to content

Commit 5bd916d

Browse files
author
Vianpyro
committed
Refactor Dockerfile to implement multi-stage builds for simplified Nuxt.js app deployment
1 parent 9c00df9 commit 5bd916d

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Dockerfile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
# Use the latest nginx as the base image
1+
# Stage 1: Build the Nuxt.js app
2+
FROM node:18-alpine AS build-stage
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json
8+
COPY package*.json ./
9+
10+
# Install dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the application code
14+
COPY . .
15+
16+
# Build the application for static hosting
17+
RUN npm run generate
18+
19+
# Stage 2: Serve the static files using Nginx
220
FROM nginx:1.27.3
321

422
# Set environment variables
@@ -13,8 +31,8 @@ RUN groupadd -r frontenduser && useradd -r -g frontenduser frontenduser
1331
# Create a directory for the PID file and assign ownership to frontenduser
1432
RUN mkdir -p /var/run/nginx && chown -R frontenduser:frontenduser /var/run/nginx
1533

16-
# Copy all files to the container
17-
COPY . /usr/share/nginx/html
34+
# Copy the generated static files from the build stage
35+
COPY --from=build-stage /app/dist /usr/share/nginx/html
1836

1937
# Copy nginx.conf to a writable location and modify the PID path
2038
RUN cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.custom && \

0 commit comments

Comments
 (0)