【问题标题】:Got errors with ONBUILD options (Docker toolbox in Windows)ONBUILD 选项出错(Windows 中的 Docker 工具箱)
【发布时间】:2016-03-28 21:52:28
【问题描述】:

我在 Windows 上的 Docker 有问题(通过 Docker 工具箱)。可能有人可以帮忙。

我没有 ONBUILD 的 Dockerfile:

FROM node:5.9.1

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app

CMD [ "npm", "start" ]
EXPOSE 3000

工作正常(docker build -t test . 并启动它:docker run -it --rm --name testrun test) 但是如果我将 Dockerfile 更改为 ONBUILD 选项:

FROM node:5.9.1

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ONBUILD COPY package.json /usr/src/app/
ONBUILD RUN npm install
ONBUILD COPY . /usr/src/app

CMD [ "npm", "start" ]
EXPOSE 3000

我收到一个错误:

npm info it worked if it ends with ok
npm info using npm@3.7.3
npm info using node@v5.9.1
npm ERR! Linux 4.1.19-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v5.9.1
npm ERR! npm  v3.7.3
npm ERR! path /usr/src/app/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.js
on'
npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.js
on'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/src/app/npm-debug.log

我做错了什么? (我是 Docker 的新手 :))。也许我错使用ONBUILD?但就像任何不清楚的东西一样没有。

【问题讨论】:

    标签: node.js windows docker npm


    【解决方案1】:

    Dockerfile man page中所述:

    ONBUILD 指令将触发指令添加到映像中,以便稍后执行,当映像用作另一个构建的基础时

    由于您没有使用以“FROM test”开头的其他图像,因此这些指令永远不会执行,这意味着test 图像不包含这些命令应该执行的操作。

    【讨论】:

      【解决方案2】:

      除非你在问题中遗漏了一些细节,否则你没有正确使用ONBUILD

      ONBUILD 选项用于将命令排队以在后续构建中运行。除非您通过将映像包含在另一个 Dockerfile 中的 FROM 引用中来包装映像,否则不会执行您上面指定的命令。

      请参阅有关此主题的Dockerfile reference 了解更多信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多