Docker copy命令从目标文件夹复制jar文件 [英] Docker copy command to copy a jar file from target folder

查看:954
本文介绍了Docker copy命令从目标文件夹复制jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven项目,将jar文件输出到目标文件夹中。我可以在Dockerfile的copy命令中使用什么相对路径来从目标文件夹中访问jar。

I have a maven project that outputs a jar file into the target folder. What relative path can i use in the copy command in the Dockerfile to access the jar from within the target folder.

推荐答案

Docker COPY 命令相对于Dockerfile位置运行。

The Docker COPYcommand runs relative to the Dockerfile location.

因此,如果您在项目的根目录中有一个Dockerfile ;与目标文件夹相同;那么简单,您可以使用:

So if you have a the Dockerfile at the root of your project; same as the target folder; then simpley you can use:

docker build。并使用 COPY target / myapp。 jar / opt / my_app / lib

另一方面,如果您具有以下项目结构:

If on the other hand you have a project structure such:


  • / docker / Dockerfile

  • / src

  • /target/myapp.jar

然后,您需要移至项目的根目录并运行:

Then you will need to move to the root of the project and run:

docker build -f docker / Dockerfile。

(请注意,您也可以导航至docker目录并运行 docker build -f dockerfile ..

(Ps you can also navigate to the docker dir and run docker build -f Dockerfile ..)

操作系统: macOS Catalina 10.15.5

Docker: 19.03.8

这篇关于Docker copy命令从目标文件夹复制jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆