那么`docker-compose up`怎么会抛出一个错误,docker run`能stream利地运行

我正在尝试使用Docker为NodeJS应用程序的开发和生产build立一个环境。 对于开发环境,我尝试使用nodemon运行应用程序(因为这会监视文件更改)。 但是,当我试图用docker-compose up运行它docker-compose up ,我得到以下错误:

错误:对于Web无法启动服务Web:oci运行时错误:container_linux.go:247:启动容器进程导致“exec:\”nodemon \“:可执行文件找不到$ PATH中”

当我运行docker run web-app (Web应用程序图像生成与docker build -t web-app .我没有任何问题,我想知道如何发生这种不同的行为,以及如何解决它。我已经把我得到的文件,以更简单的理解这个问题。


Dockerfile

 FROM node:latest # Install nodemon globally RUN npm i nodemon -g # Add local directory to /node/web-app ADD . /node/web-app # Switch to /node/web-app WORKDIR /node/web-app # Install NPM dependencies RUN npm install # Run nodemon CMD ["nodemon", "."] 

泊坞窗,compose.yml

 version: '2' services: web: build: context: . dockerfile: Dockerfile command: - nodemon . 

所以,看到你的意见。 我意识到是什么问题。 docker-compose.yml中的command指令不应该是一个列表。

把它写成string:

 command: nodemon . 

但是,由于已经在Dockerfile中声明了相同的命令,所以根本不需要将它放入docker-compose.yml


编辑:有可能把这个命令写成一个列表,但是你需要明确每个参数:

 command: - nodemon - .