Dockerfile multistage
This commit is contained in:
		
							
								
								
									
										20
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								Dockerfile
									
									
									
									
									
								
							@@ -1,21 +1,15 @@
 | 
			
		||||
# Use Node.js 24 slim image
 | 
			
		||||
FROM node:24-slim
 | 
			
		||||
 | 
			
		||||
# Set working directory
 | 
			
		||||
FROM node:24-slim AS builder
 | 
			
		||||
WORKDIR /app
 | 
			
		||||
 | 
			
		||||
# Install dependencies first (for better caching)
 | 
			
		||||
COPY package*.json ./
 | 
			
		||||
RUN npm install
 | 
			
		||||
 | 
			
		||||
# Copy the rest of the code
 | 
			
		||||
COPY . .
 | 
			
		||||
 | 
			
		||||
# Build project (for production)
 | 
			
		||||
RUN npm run build
 | 
			
		||||
 | 
			
		||||
# Expose port if needed (optional, e.g., 3000)
 | 
			
		||||
FROM node:24-slim AS production
 | 
			
		||||
WORKDIR /app
 | 
			
		||||
COPY package*.json ./
 | 
			
		||||
RUN npm install --production
 | 
			
		||||
COPY --from=builder /app/dist ./dist
 | 
			
		||||
EXPOSE 3000
 | 
			
		||||
 | 
			
		||||
# Run app in production mode
 | 
			
		||||
CMD ["node", "dist/index.js"]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										43
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								README.md
									
									
									
									
									
								
							@@ -16,3 +16,46 @@
 | 
			
		||||
- [#2 PR : feat/database_and_feed_model ](https://github.com/aabril/dailytrends/pull/2)
 | 
			
		||||
    - Añadimos `moongose` a las dependencias
 | 
			
		||||
    - Añado un docker-compose con mongo local (luego lo ampliaré para esta propia app)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Dockerfile simple to multistage
 | 
			
		||||
 | 
			
		||||
I rebuild the Dockerfile to be multistage, since the image was heavy because all the node_modules dependencies.
 | 
			
		||||
The size of the image has been reduced from 717Mb to 376.
 | 
			
		||||
 | 
			
		||||
dailytrends-app-legacy    latest    96a2dfe15361   3 minutes ago   717MB
 | 
			
		||||
dailytrends-app-light     latest    7436142e1301   3 seconds ago   376MB
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
###### legacy 
 | 
			
		||||
 | 
			
		||||
```Dockerfile
 | 
			
		||||
FROM node:24-slim
 | 
			
		||||
WORKDIR /app
 | 
			
		||||
COPY package*.json ./
 | 
			
		||||
RUN npm install
 | 
			
		||||
COPY . .
 | 
			
		||||
RUN npm run build
 | 
			
		||||
EXPOSE 3000
 | 
			
		||||
CMD ["node", "dist/index.js"]
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
###### light
 | 
			
		||||
 | 
			
		||||
```Dockerfile
 | 
			
		||||
FROM node:24-slim AS builder
 | 
			
		||||
WORKDIR /app
 | 
			
		||||
COPY package*.json ./
 | 
			
		||||
RUN npm install
 | 
			
		||||
COPY . .
 | 
			
		||||
RUN npm run build
 | 
			
		||||
 | 
			
		||||
FROM node:24-slim AS production
 | 
			
		||||
WORKDIR /app
 | 
			
		||||
COPY package*.json ./
 | 
			
		||||
RUN npm install --production
 | 
			
		||||
COPY --from=builder /app/dist ./dist
 | 
			
		||||
EXPOSE 3000
 | 
			
		||||
CMD ["node", "dist/index.js"]
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
		Reference in New Issue
	
	Block a user