-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
65 lines (46 loc) · 1.64 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Use Node.js 22 on Debian Bookworm slim variant
FROM node:22-bookworm-slim AS base
# Perform apt-get update to ensure latest versions of dependencies
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
sqlite3 libsqlite3-dev \
postgresql postgresql-client libpq-dev \
redis-server \
netcat-openbsd \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Set environment variables
ENV NODE_ENV=production
# Create a non-root user named "node"
# RUN groupadd -r node && useradd -r -g node node
# Create application directory
RUN mkdir -p /app && chown -R node:node /app
# Set working directory to /app
WORKDIR /app
# Copy package.json and package-lock.json (if available)
COPY package*.json ./
# Install application dependencies
RUN npm install --production
# Copy application source code
COPY . ./
# Change ownership of the application files to "node"
RUN chown -R node:node /app
# Copy the entrypoint script
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# Switch to the non-root "node" user
USER node
# Expose the application port (modify if necessary)
EXPOSE 3000
# Set the entrypoint script
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# Default command to start the application
CMD ["npm", "start"]
# Development stage
FROM base AS development
# Install sudo for the development environment
USER root
RUN apt-get update && apt-get install -y sudo git && rm -rf /var/lib/apt/lists/*
# Add the node user to the sudoers file
RUN echo "node ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/node && chmod 0440 /etc/sudoers.d/node
ENV NODE_ENV=development
# Switch back to the node user
USER node