How to run a jar file using docker image?

My jar runs on a specific port and I am assuming there is port for the container so how I do run a jar using the docker image? how do these ports communicate with each other? Do I need to expose both of these ports? Do I need both Entrypoint and CMD? My jar file does need to accept any arguments since it can pick the defaults.

  • Docker - Running Apache and Multiple JARs
  • Set write permission into the volume folder inside docker windows/windows container
  • Docker's container mount folder
  • Elastic Beanstalk Multicontainer Docker Environments: redirect requests between 2 APIs
  • Docker is not correctly binding ports on windows
  • Docker SIGTERM not being delivered to node.js/coffee app when started with flags
  • How to add already existing ECS Instance to newly created ECS Cluster
  • Disable ip v6 in docker container
  • How to run aiohttp with gunicorn in docker container?
  • docker - installing java 8 with curl
  • can not ssh to another Docker Container docker-compose
  • Docker building fails randomly with Error mounting
  • One Solution collect form web for “How to run a jar file using docker image?”

    If your container does not communicate with the external network (ie. the java program is the only one using those ports) then you do not need to expose the ports. Your entrypoint or cmd can be ~java -jar /my/jar and it will use your defaults.

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