linux - Windows "C:/Users/<username>/"目录在 `docker build` 命令期间不可见

标签 linux windows docker

据我所知,docker-machine自动挂载 C:/Users/<username> windows中的目录。我可以从快速启动终端访问它 /c/Users/<username>并对其执行各种操作。

然而当我RUN来自内部的命令 Dockerfile , docker 引擎根本无法识别这个挂载路径。
例如我有 activator zip 位于:

/c/Users/someuser/somefolder/typesafe-activator-1.3.10.zip

之前,我使用的是 wgetDockerfile :

RUN wget https://downloads.typesafe.com/typesafe-activator/1.3.10/typesafe-ctivator-1.3.10.zip && unzip typesafe-activator-1.3.10.zip

既然我已经在文件系统中有了这个 zip,我想:

RUN cp /c/Users/someuser/somefolder/typesafe-activator-1.3.10.zip . && unzip typesafe-activator-1.3.10.zip

但我得到:

cp:cannot stat '/c/Users/someuser/somefolder/typesafe-activator-1.3.10.zip': No such file or directory

有人知道如何从主机上的共享文件夹中获取文件到 docker 构建过程中吗?

更新 这是我的完整 Dockerfile :

FROM openjdk:8
ENV PROJECT_WORKPLACE /usr/src
RUN mkdir -p $PROJECT_WORKPLACE/activator $PROJECT_WORKPLACE/build    $PROJECT_WORKPLACE/app

WORKDIR $PROJECT_WORKPLACE/activator

COPY . typesafe-activator-1.3.10.zip
RUN unzip typesafe-activator-1.3.10 

ENV PATH $PROJECT_WORKPLACE/activator/typesafe-activator-1.3.10/activator-dist-1.3.10/bin:$PATH

COPY . $PROJECT_WORKPLACE/build

WORKDIR $PROJECT_WORKPLACE/build

RUN activator clean stage

RUN cp -R $PROJECT_WORKPLACE/build/target/universal/stage $PROJECT_WORKPLACE/app

EXPOSE 9000

CMD $PROJECT_WORKPLACE/app/stage/bin/docker-play -Dhttp.port=9000 -Dlogger.file=$PROJECT_WORKPLACE/build/logger.xml

最佳答案

RUN 看到 Dockerfile context :

上下文是当前文件夹(Dockerfile 所在的位置)及其子文件夹。

The docker build command builds an image from a Dockerfile and a context.
The build’s context is the files at a specified location PATH or URL.
The PATH is a directory on your local filesystem.
The URL is a the location of a Git repository.

A context is processed recursively. So, a PATH includes any subdirectories and the URL includes the repository and its submodules.

因此,您无需指定所有路径。

RUN cp typesafe-activator-1.3.10.zip . && unzip typesafe-activator-1.3.10.zip

注意:你应该使用COPYADD而不是 RUN cp

COPY typesafe-activator-1.3.10.zip .
RUN unzip typesafe-activator-1.3.10.zip

在任何情况下,您需要的任何资源都应位于 Dockerfile 的同一文件夹或子文件夹中。

OP egima使其适用于:

ADD typesafe-activator-1.3.10.zip .

关于linux - Windows "C:/Users/<username>/"目录在 `docker build` 命令期间不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39589006/

相关文章:

c++ - 串口打开返回EAGAIN

linux - 我想限制除 root 之外的所有用户复制、删除和褐变文件,这是可能的

linux - 是否可以使计算机充当蓝牙 HID 设备?

windows - 为什么在 ScrollViewer 内部单击时我的 TextBox 会聚焦?

docker - 如何在不以root用户身份运行的情况下读写装载的卷?

c++ - 我的简单 C 程序出现内存错误

c++ - 如何使用 C++ 在启动时打开一个新窗口?

windows - 用于禁用 Internet 选项代理服务器的批处理文件

docker 以 "failed to retrieve runc version: fork/exec/usr/bin/runc: exec format error"开头

python - 在没有docker的情况下运行正常时拒绝使用docker连接本地ip地址