【问题标题】:trouble with multiple parms and RUN多个参数和运行的问题
【发布时间】:2019-03-30 11:31:22
【问题描述】:

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

????未找到条目。 在 Bundler.bundle (/usr/local/lib/node_modules/parcel-bundler/src/Bundler.js:260:17) 在错误:服务“webapp”未能构建:命令“/bin/sh -c parcel build index.html”返回非零代码: 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" ]

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

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

# /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',但它仍然不起作用。

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

【问题讨论】:

    标签: docker dockerfile parceljs


    【解决方案1】:

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

    RUN parcel build index.html
    

    或者,如果你更喜欢明确地使用what Docker will do when it sees RUN followed by a string,你可以这样做:

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

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

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

    我会把钱放在第一个上。

    【讨论】:

    • 查看 docker CMD 的 shell 和 exec 格式的区别
    • 啊,是的!我完全错过了。感谢您指出。我没有复制其他文件,因为我在开发时使用了绑定挂载,这是在我启动容器时指定的(docker run -v ...)。生产模式会传输文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-22
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    相关资源
    最近更新 更多