-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (43 loc) · 1.93 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (43 loc) · 1.93 KB
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
49
50
51
52
53
54
55
56
57
# Use the official Ubuntu 24.04 LTS as the base image
FROM ubuntu:24.04
# Set environment variables to avoid interactive prompts during installation
ENV DEBIAN_FRONTEND=noninteractive
# Update the package list and install necessary dependencies for Node.js
# curl is needed to fetch the NodeSource setup script
# gnupg is needed to verify the authenticity of the downloaded packages
RUN apt-get update && \
apt-get install -y curl gnupg2 && \
rm -rf /var/lib/apt/lists/*
# Import the NodeSource GPG key
# This ensures that the packages you download are from a trusted source
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
# Add the NodeSource APT repository for Node.js 20.x
# Node.js 20.x is a current LTS (Long Term Support) version
# The architecture is dynamically detected using $(dpkg --print-architecture)
ENV NODE_MAJOR=20
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
# Update the package list again to include the new NodeSource repository
# Install Node.js and npm
# npm is installed automatically with nodejs
RUN apt-get update && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*
# Verify Node.js and npm installation
RUN node -v
RUN npm -v
# Set the working directory
WORKDIR /app
# Copy application code into the container
COPY ./code /app
# Install application dependencies
RUN npm install
# Build application
RUN npm run build
# Create a new "config" directory inside /app/server if it doesn't already exist
RUN mkdir -p /app/server/config
# Remove config.json if it exists (the config volume will be mapped into the container from the host)
RUN rm -f /app/server/config/config.json
# Expose a port
EXPOSE 8080
# Define the command to run the application when the container starts
CMD ["node", "dist/server/Server.js"]