dockerfile
FROM node:${NODE_VERSION}-buster-slim
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
RUN apt-get update && \
apt-get install -qqy --no-install-recommends \
ca-certificates \
dumb-init \
build-essential && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV HOME=/home/node
WORKDIR $HOME/app
COPY --chown=node:node . .
RUN set -xe && \
chown -R node /usr/local/lib /usr/local/include /usr/local/share /usr/local/bin && \
npm install && npm cache clean --force
EXPOSE 4200
CMD ["node"]
docker-compose
webapp :
container_name : webapp
hostname : webapp
build :
dockerfile : Dockerfile
context : ${PWD}/app
image : webapp:development
command :
- npm install
- npm run start
volumes :
- ${PWD}/webapp:/app
networks :
- backend
ports :
- 4200:4200
restart : on-failure
tty : true
stdin_open : true
env_file :
- variables.env
我可以运行图像
docker run webapp bash -c "npm install; npm run start"
但是当我运行撰写文件时,它说
webapp | [dumb-init] npm install: No such file or directory
我尝试将docker-compose命令替换为前缀“ node”,但出现相同的错误,但是使用节点npm install:没有这样的文件或目录
有人可以告诉我哪里出了问题吗?
答案 0 :(得分:1)
在command:
文件中使用docker-compose.yml
的列表形式(或Dockerfile CMD
的JSON数组形式)时,您将在单个命令中提供单词列表,不是单独命令的列表。将其与Dockerfile中的ENTRYPOINT
组合后,容器命令为
/usr/bin/dumb-init -- 'npm install' 'npm run start'
如果没有/usr/bin/npm\ install
文件(包括文件名中的空格),则会出现该错误。
由于您在Dockerfile中COPY
使用了应用程序代码并在其中运行npm install
,因此您无需在应用程序启动时重复此步骤。您应该能够删除volumes:
文件的command:
和docker-compose.yml
部分,以使用图像内置的内容。
如果您确实需要重复此command:
,请按照docker run
命令中指定的格式进行操作,而无需使用列表语法
command: bash -c 'npm install; npm run start'