Java – how to create docker image files and value parameters for local applications

I have a Java application (jar file) that I want to be able to run from the dock image

I created a docker file to create an image based on CentOS and installed Java itself:

Dockerfile
FROM centos
RUN yum install -y java-1.7.0-openjdk

I run docker build - t me / java7 to get the image

But I fell into some dead ends

>How to copy jar files from host to image / container > I need 2 parameters 1 is a file that needs to be copied to the container at run time The other is a number, which needs to be automatically passed to the jar file in the Java jar command. When the user runs docker with parameters

Additional remarks:

The jar file is a local file You can't access anywhere through WGet or anything At present, the closest is the windows share containing it I can also access the source code from the GIT repository, but this will involve compiling everything and installing Maven and git on the image, so I'd rather avoid this

Thank you for any help

Solution

>In the docker file, use add to add local files, such as

ADD your-local.jar /some-container-location

>You can use volumes to place files in containers at run time, such as

VOLUME /copy-into-this-dir

Then you run using

docker run -v=/location/of/file/locally:/copy-into-this-dir -t me/java7

You can pass parameters using entrypoint and CMD, for example

ENTRYPOINT ["java","-jar","/whatever/your.jar"]
CMD [""]

Then run it

docker run -v=/location/of/file/locally:/copy-into-this-dir -t me/java7 --myNumber 42

(see dockerfile documentation)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>