DockerFile to run a java program

前端 未结 8 1545
礼貌的吻别
礼貌的吻别 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:40

    You can save yourself by writing DockerFile as well, just have java image in your local image repo, compile and run your java program by passing your program to it, its very easy.

    $ docker run java:alpine java -version
    
    $ docker run --rm -v $PWD:/app -w /app java:alpine javac Main.java
    
    $ docker run --rm -v $PWD:/app -w /app java:alpine java Main
    
    0 讨论(0)
  • 2021-02-19 16:51

    Another way to run it could be with a shell file.

    CMD ["/bin/bash", "-ex", "run.sh"]
    

    and in your run.sh file you can run the javac and java commands.

    0 讨论(0)
提交回复
热议问题