【问题标题】:docker-compose trying to run sh script (npm / ng serve) but cannot find directorydocker-compose 试图运行 sh 脚本(npm / ng serve)但找不到目录
【发布时间】:2018-08-21 07:07:55
【问题描述】:

我在docker-compose 上有这部分,它将复制angular-cli 前端和scripts 目录。

  www:
    build: ./www
    volumes:
      - ./www/frontend:/app
      - ./www/scripts:/scripts
    command: /scripts/init-dev.sh
    ports:
      - "4200:4200"
      - "49153:49153"

www 中的Dockerfile 将安装 npm。

FROM node:10-alpine
RUN apk add --no-cache git make curl gcc g++ python2

RUN npm config set user 0
RUN npm config set unsafe-perm true

RUN npm install

还有脚本:

#!/bin/bash
echo "Serving.."
cd /app && npm run-script start

我正在运行docker-compose down && docker-compose build && docker-compose up 命令:

www_1       | standard_init_linux.go:190: exec user process caused "no such file or directory"

我假设错误来自command 行。

【问题讨论】:

  • 您在 Windows 主机上吗?基于 Alpine 的容器实际上有 bash,还是使用了更轻量级的 POSIX shell?

标签: docker npm docker-compose angular-cli


【解决方案1】:

很可能您的操作顺序错误。

我不是 Node 方面的专家,但您需要一个 package.json 或其他任何东西来让 npm install 完成这项工作。我猜它在 /app 中。但在构建时,/app 无处可见,因为 Dockerfile 中没有提及它。

尝试在脚本中移动npm installcd /app && npm install && npm run-script start

【讨论】:

    【解决方案2】:

    遇到过类似的问题,可以试试给这个文件添加execute权限

    chmod +x www/scripts/init-dev.sh
    

    【讨论】:

      猜你喜欢
      • 2022-01-26
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 2019-08-30
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多