How to run executable jar in docker

a jar need to deploy in docker.I know how to write Dockerfile for a running jar.
this jar is a commandline option has serveral arguments.and will be needed to run serveral times with different arguments.
for has arg1,arg2.

user can run with arg1=A,arg2=B then
run with arg1=A2.No arg2.

  • How to obtain container Ip from another container?
  • I started a docker container with --rm Is there an easy way to keep it, without redoing everything?
  • Docker-Compose: how to mapping volume from host into container?
  • “tag latest not found” on docker pull with private registry
  • docker login behind proxy on private registry gives TLS handshake timeout
  • Default docker machine on Mac
  • docker cannot run this,have specified these arguments when they run.and the container stop once the jar main task finished.need to start another container to run jar.

    Don’t think this is question is

    in this case,is it not suitable to deloy with docker?

  • Customisation of the official Selenium Hub docker image returns 'Permission denied'
  • Linux command output as input at particular location of another command.?
  • docker-compose - No such service via Vagrant-Windows shells only
  • example marathon json deployment file when using glusterfs volume driver
  • How to get ssh connection with docker container on OSX(boot2docker)
  • Where are the downloaded docker images on my mac? Any fixed directory?
  • 2 Solutions collect form web for “How to run executable jar in docker”

    You can configure the container to run a script that will never end just to keep the container running.
    As an example you can include the following in the Dockerfile:

    RUN echo 'sleep infinity' >> / && chmod +x /

    You can start the container in the following way:

    docker run -d --name <container-name> <image> ./

    To run the jar you can use:

    docker exec <container-name> java [arguments]

    Having in mind it is a java program and it is OS agnostic you don’t have a huge benefit in running inside a container but is possible.

    You can use a simple “hack” for this purpose… But I do not think this is the best solution.

    Start a container with a process that is not supposed to be ended soon, e.g. bash. Also, lets say you want to use the latest ubuntu image. Then you can start the container with:

    $ docker run -d -it ubuntu bash

    This starts a ubuntu container and keeps it running as a daemon edit: detached (-d) in the background.

    Lets lookup the container’s name:

    $ docker ps -a
    59104211e795   ubuntu   "bash"    2 seconds ago   Up 1 seconds   jolly_hawking

    It is jolly_hawking. Your commands (here: ls /) can then be sent to the container with this command:

    $ docker exec jolly_hawking ls /

    But that is definitely not the best solution. Maybe just keep this as an example how this might work for you and how Docker containers are working.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.