简体   繁体   English

Dockerfile运行可执行文件

[英]Dockerfile run executable

I'm having a directory that contains a Dockerfile and a JAR file foo.jar . 我有一个包含Dockerfile和JAR文件foo.jar

In the Dockerfile I've written the following: Dockerfile我写了以下内容:

FROM java:8
EXPOSE 8080
ENTRYPOINT ["java","-jar","foo.jar"]

I build the image with success by running 我通过运行成功构建了映像

docker build -t foo-example .

Then I try to run it by running 然后我尝试通过运行来运行它

docker run -ti --rm -p 8080:8080 foo-example

and I'm getting this error: 我收到这个错误:

Error: Unable to access jarfile foo.jar

Any ideas? 有任何想法吗?

You should use docker COPY or ADD command. 您应该使用docker COPY或ADD命令。 COPY is more preferred as described here: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#add-or-copy 如下所述,COPY更受欢迎: https//docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#add-or-copy

FROM java:8
EXPOSE 8080
COPY foo.jar ~/.
ENTRYPOINT ["java","-jar","foo.jar"]

You need to make foo.jar available inside the container, eg copy it inside and make sure to specify exact location while executing it. 您需要在容器内部提供foo.jar ,例如将其复制到内部并确保在执行时指定确切的位置。 Read docker docs about ADD command. 阅读有关ADD命令的docker文档。

Basically you need to add something along these lines: 基本上你需要在这些方面添加一些东西:

ADD foo.jar foo.jar

Using COPY is another alternative: 使用COPY是另一种选择:

COPY foo.jar ~/.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM