0

This is my Dockerfile:

# Stage 1: Build the Angular app
FROM node:18 AS builder

WORKDIR /app

# Copy package.json and package-lock.json to install dependencies
COPY package.json package-lock.json ./

# Install Angular CLI globally
RUN npm install -g @angular/cli

# Install app dependencies
RUN npm install

# Clear Angular cache
RUN npx ngcc --clearCache

# Copy the entire Angular app source code to the container
COPY . .

# Build the Angular app for production
RUN ng build --base-href=/platform/ --configuration production --verbose

# Stage 2: Serve the Angular app using Nginx
FROM nginx:latest

# Copy the built Angular app from the previous stage to Nginx's default public directory
COPY --from=builder /app/dist/platform-ui /usr/share/nginx/html

# Copy a custom Nginx configuration if needed (e.g., for handling routing)
# COPY nginx.conf /etc/nginx/conf.d/default.conf

# Expose port 80 (default HTTP port for Nginx)
EXPOSE 80

Very simple file to build an angular application but each time build gets stuck in the build step RUN ng build --base-href=/platform/ --configuration production --verbose with the following error:

[webpack.cache.PackFileCacheStrategy] No pack exists at /app/.angular/cache/17.3.2/angular-webpack/d7b86a
 => => # c41a517ca254ba61ce464bfbbe390ffa5f.pack: Error: ENOENT: no such file or directory, stat '/app/.angular/cache/
 => => # 17.3.2/angular-webpack/d7b86ac41a517ca254ba61ce464bfbbe390ffa5f/index.pack'

I've tried to clean docker build's cache with the following command docker builder prune -a -f but still the same error, not sure why angular keeps reaing a cache although it's docker build, it's supposed to be an empty environment!!

1 Answer 1

1

The problem is probably that the local Angular cache files are being copied to your docker image. Here is how you can fix it:

Sign up to request clarification or add additional context in comments.

2 Comments

sorry this didn't work, I don't even have .angular folder but I've added it anyway, also added the ng cache disable before the build command stilll same problem, the process is stuck in the build step...
the problem is that when it gets stuck I have to reboot my ec2 instance because it becomes unaccessible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.