关于dockerfile:Docker ONBUILD COPY似乎不复制文件

Docker ONBUILD COPY doesn't seem to copy files

当我执行docker build命令时,我正在尝试将文件复制到docker映像。我不确定我做错了什么,因为这似乎适用于Docker Rails onBuild文件,但不适用于我的自定义DockerFile。

这是我的码头文件

1
2
3
4
5
6
7
8
FROM ubuntu:14.04

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

ONBUILD COPY Gemfile /usr/src/app

CMD ["tail","-f","/dev/null"]

我运行的docker命令如下。

1
2
3
docker build -t copy-test .
docker run --name run-test -d copy-test
docker exec -i -t 2e9adebae0fc /bin/bash

当我用docker exec连接到容器时,它从/usr/src/app开始,但gemfile不在那里。我不明白为什么mkdir和workdir指令看起来有效,但是onbuild拷贝不起作用。(是的,我在其中调用这些命令的目录确实有一个gemfile)


你必须用COPY来建立你的形象。如果您的图像是构建其他图像的模板,请使用ONBUILD

见Docker文件:

The ONBUILD instruction adds to the image a trigger instruction to be executed at a later time, when the image is used as the base for another build. The trigger will be executed in the context of the downstream build, as if it had been inserted immediately after the FROM instruction in the downstream Dockerfile.