如何为本地应用程序创建Docker映像文件和值参数 [英] How to create docker image for local application taking file and value parameters
问题描述
我已经创建了一个Docker文件来创建一个使用centos作为基础,并安装java本身:
Dockerfile
FROM centos
运行yum install -y java -1.7.0-openjdk
我运行 docker build -t me / java7
之后获取图像我/ java7
但是我陷入了一些死胡同。
- 如何将jar文件从主机复制到图像/容器中
- 我需要2个参数。 1是一个文件,需要在运行时将其复制到容器中的目录中。另一个是当用户运行
docker run $ c时,需要在
java -jar
命令中传递给jar文件的数字$ c>带有参数
额外注意:
该jar文件是一个本地文件。通过wget或任何东西无法访问任何地方。目前最接近的是包含它的Windows共享。我也可以从git存储库访问源代码,但这将涉及到编译所有内容,并在图像上安装maven和git,所以我宁愿避免使用。
任何帮助非常感谢。
-
在Dockerfile中,使用ADD添加本地文件,例如
添加your-local.jar / some-container-location
-
您可以使用卷在运行时将文件放在容器中,例如
VOLUME / copy-into-this-dir
然后运行使用
docker run -v = / location / of / file / local:/ copy-into-this-dir -t me / java7
您可以使用ENTRYPOINT和CMD传递参数,例如
ENTRYPOINT [java,-jar,/whatever/your.jar]
CMD []
然后再次使用
docker运行-v = / l ocation / of / file / local:/ copy-into-this-dir -t me / java7 --myNumber 42
(请查看 Dockerfile文档。)
I have a java application (jar file) that I want to be able to run from a docker image.
I have created a Dockerfile to create an image using centos as base and install java as such:
Dockerfile
FROM centos
RUN yum install -y java-1.7.0-openjdk
I ran docker build -t me/java7
after to obtain the image me/java7
however I am stuck at some dead ends.
- How do I copy the jar file from the host into the image/container
- I require 2 parameters. 1 is a file, which needs to be copied into a directory into the container at runtime. The other is a number which needs to be passed to the jar file in the
java -jar
command automatically when the user runsdocker run
with the parameters
Extra Notes:
The jar file is a local file. Not hosted anywhere accessible via wget or anything. The closest I have at the moment is a windows share containing it. I could also access the source from a git repository but that would involve compiling everything and installing maven and git on the image so I'd rather avoid that.
any help is much appreciated.
In the Dockerfile, add a local file using ADD, e g
ADD your-local.jar /some-container-location
You could use volumes to put a file in the container in runtime, e g
VOLUME /copy-into-this-dir
And then you run using
docker run -v=/location/of/file/locally:/copy-into-this-dir -t me/java7
You can use ENTRYPOINT and CMD to pass arguments, e g
ENTRYPOINT ["java", "-jar", "/whatever/your.jar"] CMD [""]
And then again run using
docker run -v=/location/of/file/locally:/copy-into-this-dir -t me/java7 --myNumber 42
(Have a look at the Dockerfile documentation.)
这篇关于如何为本地应用程序创建Docker映像文件和值参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!