0

I'm trying to containerize my Angular app using Docker.

I'm pretty new to Docker, hence I followed a tutorial, adding a Dockerfile with the following content:

FROM node:13.3.0 AS compile-image

WORKDIR /usr/src/app
COPY package.json package-lock.json ./

RUN npm install

ENV PATH="./node_modules/.bin:$PATH"

COPY . ./
RUN ng build --prod

FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=compile-image /opt/ng/dist/myproject /usr/share/nginx/html

But somehow it fails at Step 9/10 returning following error:

COPY failed: stat /var/lib/docker/tmp/docker-builder934487773/nginx.conf: no such file or directory

6
  • Hi, did you create a nginx.conf file while following the tutorial ? Commented Jun 25, 2020 at 10:19
  • @ukpillai Didn't come up in the tutorial - do you have some instructions? Commented Jun 25, 2020 at 12:10
  • That is the reason why step 9 (copying nginx.conf) is failing. I would say remove the step 9 and rebuild. Commented Jun 25, 2020 at 12:45
  • @ukpillai what are the consequences of not having such file? And removing step 9 obviously helps, but somehow I get a similar error for former step 10 now: stat /var/lib/docker/overlay2/9240a4bec850e1e39aabeb7b6d37c1cdfdb078743bd77fe426484267aad37a03/merged/opt/ng/dist/myproject: no such file or directory Commented Jun 25, 2020 at 14:27
  • 1
    Okay, nginx.conf file is a primary config file for nginx, where in you set directive for handling web traffic, location of your website configuration files etc. Now the error is due to WORKDIR which is set wrong. I dont know what your use case is, but I am assuming you want to serve static assets from nginx. based on that I will try to add few details into the answer section. Commented Jun 25, 2020 at 14:49

2 Answers 2

4

Modified the Dockerfile, you can start from this and update as required.

FROM node:13.3.0 AS compile-image    
COPY package.json package-lock.json ./    
RUN npm install && mkdir /angular-app
ENV PATH="./node_modules/.bin:$PATH"
WORKDIR /angular-app
COPY . .
RUN ng build --prod
FROM nginx
RUN rm -rf /usr/share/nginx/html/*
COPY --from=compile-image /angular-app/dist /usr/share/nginx/html

You can refer to nginx.conf documentation from http://nginx.org/en/docs/beginners_guide.html & if it is needed create the conf file and add a COPY statement in dockerfile

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

Comments

0

Having the docker-compose and the dockerfile in the same folder might work.

1 Comment

I'm new to docker. What does this mean? Where's my docker-compose, how do I relocate it?

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.