简体   繁体   English

使用 Docker 构建 Angular 失败:nginx.conf - 没有这样的文件

[英]Building Angular with Docker fails: nginx.conf - no such file

I'm trying to containerize my Angular app using Docker.我正在尝试使用 Docker 将我的 Angular 应用程序容器化。

I'm pretty new to Docker, hence I followed a tutorial, adding a Dockerfile with the following content:我对 Docker 很陌生,因此我按照教程添加了一个Dockerfile ,内容如下:

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:但不知何故,它在步骤 9/10 失败,返回以下错误:

COPY failed: stat /var/lib/docker/tmp/docker-builder934487773/nginx.conf: no such file or directory复制失败:stat /var/lib/docker/tmp/docker-builder934487773/nginx.conf:没有这样的文件或目录

Modified the Dockerfile, you can start from this and update as required.修改了Dockerfile,可以从这里开始,按需更新。

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 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

Having the docker-compose and the dockerfile in the same folder might work.将 docker-compose 和 dockerfile 放在同一个文件夹中可能会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM