从 Dockerfile 构建时如何访问本地文件?
How to access local file when building from Dockerfile?
我从 Dockerfile 构建时需要 hello.rpm
,但是这个 rpm 文件无法在线获得。
现在我正在通过启动一个临时网络服务器来提供文件,但理想情况下我想 运行 一个 build 命令使这个本地化文件在容器内可用。
这可能吗?
我的构建命令:
docker build -t fredrik/helloworld:1.0 .
我的 Dockerfile:
FROM centos:6
RUN rpm -ivh hello.rpm
为什么不在执行前COPY容器内的文件RUN
?
FROM centos:6
COPY hello.rpm /tmp/hello.rpm
RUN rpm -ivh /tmp/hello.rpm
这假定 hello.rpm
在您构建它时紧挨着您的 Dockerfile
。
否则,如果互联网连接不是您工作时的限制因素:
- 将文件上传到云端作为 Dropbox
- 转到您的 docker shell 和
wget https://www.cloudnameXYZ.com/filename
我从 Dockerfile 构建时需要 hello.rpm
,但是这个 rpm 文件无法在线获得。
现在我正在通过启动一个临时网络服务器来提供文件,但理想情况下我想 运行 一个 build 命令使这个本地化文件在容器内可用。
这可能吗?
我的构建命令:
docker build -t fredrik/helloworld:1.0 .
我的 Dockerfile:
FROM centos:6
RUN rpm -ivh hello.rpm
为什么不在执行前COPY容器内的文件RUN
?
FROM centos:6
COPY hello.rpm /tmp/hello.rpm
RUN rpm -ivh /tmp/hello.rpm
这假定 hello.rpm
在您构建它时紧挨着您的 Dockerfile
。
否则,如果互联网连接不是您工作时的限制因素:
- 将文件上传到云端作为 Dropbox
- 转到您的 docker shell 和
wget https://www.cloudnameXYZ.com/filename