-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
48 lines (36 loc) · 1.14 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Use the official lightweight Node.js 18 image.
# https://hub.docker.com/_/node
FROM node:18-slim
# Set the working directory
WORKDIR /usr/src/app
# Declare build-time arguments for database configuration
ARG DB_HOST
ARG DB_PORT
ARG DB_DATABASE
ARG DB_USER
ARG DB_PASSWORD
# Set the environment variables from build arguments
ENV DB_HOST=${DB_HOST}
ENV DB_PORT=${DB_PORT}
ENV DB_DATABASE=${DB_DATABASE}
ENV DB_USER=${DB_USER}
ENV DB_PASSWORD=${DB_PASSWORD}
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install --frozen-lockfile
# Copy the rest of the application code
COPY . .
# Build the Next.js application
RUN npm run build
# If you're using Next.js 12 or newer, you need to install sharp for image optimization
# RUN npm install sharp
# Set the default port to 8080
ENV PORT 8080
# Allow the port to be customizable through an environment variable
ARG CC_DOCKER_EXPOSED_HTTP_PORT
ENV PORT ${CC_DOCKER_EXPOSED_HTTP_PORT:-8080}
# Inform Docker that the container is listening on the specified port at runtime.
EXPOSE ${PORT}
# Set the default command to run when starting the container
CMD ["npm", "start"]