forked from waldemarnt/node-docker-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
31 lines (23 loc) · 1 KB
/
Dockerfile
File metadata and controls
31 lines (23 loc) · 1 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
# 1. Use a supported Node.js image (This fixes the 'stretch' EOL problem)
FROM node:20-slim
# Set the working directory variable (optional, but good practice)
ENV HOME=/home/app
ENV APP_DIR=$HOME/node_docker
# 2. Update package lists and install necessary Linux utilities (like htop)
# The node:slim image is based on Debian, so apt-get works.
RUN apt-get update && apt-get install -y htop \
&& rm -rf /var/lib/apt/lists/* # Clean up cache to keep image small
# Create the application directory
RUN mkdir -p $APP_DIR
# 3. Copy only the dependency files first
# This ensures faster rebuilds (Docker caching) if only source code changes.
COPY package.json package-lock.json $APP_DIR/
# 4. Set the working directory inside the container
WORKDIR $APP_DIR
# 5. Install dependencies
# Using --prefer-offline saves time if npm cache is available
RUN npm install --silent --progress=false
# 6. Copy the rest of the application source code
COPY . $APP_DIR
# 7. Define the command to start the application
CMD ["npm", "start"]