运行 dockerfile 中的可执行文件

Running an executable in a dockerfile

我是 Docker 的新手,正在通读 Turnbull 的 Docker 书。 本质上,我掌握了容器如何工作以及镜像如何在传输协议和虚拟化操作系统中工作的术语和过程。

但是,我的 docker 文件不是 运行 本地可执行文件,我不知道如何将我的本地可执行文件添加到容器的 /bin 目录中。

我的目标:我想将 name.exe 添加到我容器的 /bin 目录中。然后我想要一个 docker 文件是

FROM ubuntu
MAINTAINER me@gmail.com
RUN ["name.exe", "input1", "output"]

并让我的容器 运行 我的程序,并创建一个输出。 我的目标是让他们将我的容器放到我的存储库中,并与我编写的所有 /bin 程序一起共享它。

但是,我做不到。

尝试:

FROM ubuntu
ADD name.exe /bin/name.exe
ENTRYPOINT["name.exe"]
CMD["input1","input2"]

但是这个 input1 input2 也必须在 docker 上,否则你必须在 运行

时添加 -v

基本上,"add" 命令将文件从您的本地系统复制到 docker 映像中。

更多信息请看这里: https://docs.docker.com/reference/builder/#add

请记住 name.exe 必须与您的 dockerfile 位于同一目录中。 From the documentation:

The <src> path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

您的 dockerfile 可能如下所示:

FROM ubuntu
MAINTAINER me@gmail.com
COPY name.exe /bin/
CMD ["/bin/name.exe", "input1", "output"]

你可以像这样构建它:

docker build --tag=me/my-image .

当你 运行 它 (docker run me/my-image) 时,它会 运行 /bin/name.exe input1 output.