0

我正在尝试让 Parcel Bundler 从 Dockerfile 中构建资产。但它失败了:

未找到条目。在 Bundler.bundle (/usr/local/lib/node_modules/parcel-bundler/src/Bundler.js:260:17) at ERROR: Service 'webapp' failed to build: The command '/bin/sh -c parcel build index.html' 返回一个非零代码:1

这是我的码头文件:

FROM node:8 as base
WORKDIR /usr/src/app
COPY package*.json ./

# Development
FROM base as development
ENV NODE_ENV=development
RUN npm install
RUN npm install -g parcel-bundler
WORKDIR /usr/src/app
RUN parcel build index.html     <----- this is where its failing!
#RUN parcel watch index.html
# Uncomment to use Parcel's dev-server
#CMD [ "npm", "run", "parcel:dev" ]
#CMD ["npm", "start"]

# Production
FROM base as production
ENV NODE_ENV=production
COPY . .
RUN npm install --only=production
RUN npm install -g parcel-bundler
RUN npm run parcel:build
CMD [ "npm", "start" ]

注意:我试图让它首先在开发模式下运行。

当我“登录”容器时,我发现这个命令确实失败了:

# /bin/sh -c parcel build index.html

但这有效:

# parcel build index.html 

这有效:

# /bin/sh -c "parcel build index.html"

但是在 Dockerfile 中使用这些变体仍然不起作用:

RUN /bin/sh -c "parcel build index.html"

或者

RUN ["/bin/sh", "-c", "parcel build index.html"]

注意:我也尝试了 'bash' 而不是 'sh',但它仍然不起作用。

任何想法为什么它不起作用?

4

1 回答 1

1

bash确实是不同的贝壳,sh但在这里应该没关系。 -c "command argument argument"将整个 shell 字符串传递给-c,而-c command argument argument仅传递command-c将参数解释为您正在调用的 shell 的附加命令。所以正确的调用确实是:

RUN parcel build index.html

或者,如果您更愿意明确执行Docker 在看到 RUN 后跟 string 时将执行的操作,您可以执行以下操作:

RUN [ "bash", "-c", "parcel build index.html" ]

但我认为这些都不是你的问题。查看您的 docker 文件,我认为您可能是:

  • 缺少一些 Bundler 需要的文件(此时您只复制了package*.json
  • 缺少一些 Bundler 需要运行的额外配置(我没有看到您明确设置“webapp”,但可能在package*.json文件中)

我会把钱放在第一个。

于 2018-10-25T19:04:18.923 回答