Docker /docker-entrypoint.sh:32:exec:yarn:运行docker容器时找不到(Angular)

问题描述 投票:0回答:1

我正在尝试在 Docker 容器中构建一个 Angular 应用程序。我成功构建了一个 docker 映像并从中创建了一个容器,但是当我运行它时,我得到了

/docker-entrypoint.sh: 32: exec: yarn: not found
。这是我的 Dockerfile:

FROM node:13.3.0 AS compile-image
RUN npm install -g yarn
WORKDIR /opt/ng 
COPY package.json yarn.lock angular.json ./
RUN yarn
RUN yarn install
COPY . ./ 
RUN node_modules/.bin/ng build --prod
FROM nginx
COPY --from=compile-image /opt/ng/dist/dashboard /usr/share/nginx/html
CMD ["yarn", "start"]

据我了解,

Run yarn
失败了,但我很困惑为什么
RUN npm install -g yarn
应该安装它。我是 Docker 新手,如果我得出错误的结论,我很抱歉。

angular docker yarnpkg
1个回答
4
投票

请使用

nginx:1.18-alpine
并从包管理器安装yarn
npm install -g yarn

FROM node:13.3.0 AS compile-image
RUN npm install -g yarn
WORKDIR /opt/ng 
COPY package.json yarn.lock angular.json ./
RUN yarn
RUN yarn install
COPY . ./ 
RUN node_modules/.bin/ng build --prod
FROM nginx:1.18-alpine
RUN apk add yarn
COPY --from=compile-image /opt/ng/dist/dashboard /usr/share/nginx/html
CMD ["yarn", "start"]

此外,请确保更改为您的要求。

© www.soinside.com 2019 - 2024. All rights reserved.