1

I'm trying to Dockerize an Angular project This is my Dockerfile:

# 1. Build our Angular app
FROM node:12 as builder

WORKDIR /app
COPY package.json package-lock.json ./
ENV CI=1
RUN npm ci

COPY . .
RUN npm run build-web --output-path=/dist
RUN ls

# 2. Deploy our Angular app to NGINX
FROM nginx:alpine

## Replace the default nginx index page with our Angular app
RUN rm -rf /usr/share/nginx/html/* 
COPY --from=builder /dist /usr/share/nginx/html

COPY ./.nginx/nginx.conf /etc/nginx/nginx.conf

ENTRYPOINT ["nginx", "-g", "daemon off;"]

But there is an error:

[stage-1 3/4] COPY --from=builder /dist /usr/share/nginx/html:                                                                                                                                           

What is the problem?

1
  • 1
    You're building your first stage in /app, but you COPY --from=builder /dist out of that image's root directory. Change it to /app/dist to match.
    – David Maze
    Commented Jul 16, 2022 at 10:07

1 Answer 1

0

In the building state, your working directory is "/app", all of your files are under the "/app" directory.

In the second state, you try to copy a file from "/dist", Change path of the source file from "/dist" to "/app/dist"

COPY --from=builder /app/dist /usr/share/nginx/html
1
  • which means that the absolute output-path set in this line: "RUN npm run build-web --output-path=/dist" is completely ignored? or is it relative, even though starting with a "/"? Commented Oct 29, 2024 at 22:32

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.