Skip to content

Commit f90e76b

Browse files
Update dockerfile
1 parent 2ffe064 commit f90e76b

File tree

4 files changed

+1248
-29
lines changed

4 files changed

+1248
-29
lines changed

Dockerfile

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
1-
# Stage 1: Build the Application
2-
# We use node:22 as the base for building and installing dependencies.
3-
FROM node:22 AS build
1+
# syntax = docker/dockerfile:1
42

5-
# Set the working directory inside the container
6-
WORKDIR /usr/src/app
3+
# Adjust NODE_VERSION as desired
4+
ARG NODE_VERSION=22.16.0
5+
FROM node:${NODE_VERSION}-slim AS base
76

8-
# Copy package.json and package-lock.json first to leverage Docker caching.
9-
# If these files don't change, subsequent builds can skip 'npm install'.
10-
COPY package*.json ./
7+
LABEL fly_launch_runtime="Node.js"
118

12-
# Install dependencies
13-
RUN npm install
9+
# Node.js app lives here
10+
WORKDIR /app
1411

15-
# Copy the rest of the application source code
16-
COPY . .
12+
# Set production environment
13+
ENV NODE_ENV="production"
14+
ARG YARN_VERSION=1.22.5
15+
RUN npm install -g yarn@$YARN_VERSION --force
16+
17+
18+
# Throw-away build stage to reduce size of final image
19+
FROM base AS build
1720

18-
# Stage 2: Create the Final Production Image
19-
# We use node:22 as the runtime image with all the necessary tools.
20-
FROM node:22
21+
# Install packages needed to build node modules
22+
RUN apt-get update -qq && \
23+
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3
2124

22-
# Set the working directory
23-
WORKDIR /usr/src/app
25+
# Install node modules
26+
COPY package-lock.json package.json yarn.lock ./
27+
RUN yarn install --frozen-lockfile
28+
29+
# Copy application code
30+
COPY . .
2431

25-
# Copy the node_modules and built application files from the 'build' stage
26-
COPY --from=build /usr/src/app/node_modules ./node_modules
27-
COPY --from=build /usr/src/app/package*.json ./
28-
COPY --from=build /usr/src/app .
2932

30-
# Expose the port your app runs on
31-
ENV PORT=8080
32-
EXPOSE $PORT
33+
# Final stage for app image
34+
FROM base
3335

34-
# Run the application using the non-root user (recommended for security)
35-
USER node
36+
# Copy built application
37+
COPY --from=build /app /app
3638

37-
# Define the command to start your application
38-
CMD [ "node", "index.js" ]
39+
# Start the server by default, this can be overwritten at runtime
40+
EXPOSE 3000
41+
CMD [ "yarn", "run", "start" ]

0 commit comments

Comments
 (0)