多个参数和 运行 的问题

trouble with multiple parms and RUN

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

No entries found. at 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' returned a non-zero code: 1

这是我的 dockerfile:

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" ]

注意:我试图先在开发模式下将其设置为 运行。

当我"log into"容器的时候,我发现这条命令确实失败了:

# /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',但仍然没有用。

知道为什么它不起作用吗?

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

RUN parcel build index.html

或者,如果您更愿意明确地执行 ,您可以执行:

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

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

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

我会把钱花在第一个上。