DockerFile to run a java program

前端 未结 8 1507
礼貌的吻别
礼貌的吻别 2021-02-19 16:10

Hi I\'m new to Docker and trying out to write a new image from the scratch. I am writing this dockerFile to compile and run a simple java program available in the same directory

8条回答
  •  一个人的身影
    2021-02-19 16:26

    Another way...

    1. you have to use "java:8" as base image or install jdk on "ubuntu" image.
    2. build the image

      docker build -t imagename .
      
    3. run it(mounting Helloworld.java to container)

      docker run -it -v ~/system-path:/javafolder imagename
      

    type these commands to execute inside container-

    cd javafolder
    
    javac HelloWorld.java
    
    java HelloWorld
    

提交回复
热议问题