我正在尝试在 docker 容器内以开发模式运行角度应用程序,但是当我使用 docker-compose build 运行它时,它可以正常工作,但是当我尝试放置容器时,我收到以下错误:
ERROR: for sypgod Cannot start service sypgod: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"npm\": executable file not found in $PATH
真正的问题是它无法识别命令 npmserve,但为什么?
设置如下:
Docker 容器(Nginx 反向代理 -> Angular 在端口 4000 中运行)
我知道有更好的部署方法,但目前出于某些个人原因我需要此设置
Dockerfile:
FROM node:10.9
COPY package.json package-lock.json ./
RUN npm ci && mkdir /angular && mv ./node_modules ./angular
WORKDIR /angular
RUN npm install -g @angular/cli
COPY . .
FROM nginx:alpine
COPY toborFront.conf /etc/nginx/conf.d/
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
CMD ["npm", "serve", "--port 4000"]
Nginx服务器站点
server{
listen 80;
server_name sypgod;
location / {
proxy_read_timeout 5m;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:4000/;
}
}
Docker Compose 文件(我遇到问题的重要部分)
sypgod: # The name of the service
container_name: sypgod # Container name
build:
context: ../angular
dockerfile: Dockerfile # Location of our Dockerfile