嗨,我是新來的Docker,並試圖從頭開始寫一個新的圖像。我正在編寫這個dockerFile來編譯和運行一個簡單的java程序在同一個目錄下。DockerFile運行一個java程序
這是dockerfile。
FROM scratch
CMD javac HelloWorld.java
CMD java HelloWorld
泊塢構建成功如下圖所示
[[email protected] myjavadir]# docker build -t runhelloworld .
Sending build context to Docker daemon 3.072 kB
Sending build context to Docker daemon
Step 0 : FROM scratch
--->
Step 1 : CMD javac HelloWorld.java
---> Running in 7298ad7e902f
---> f5278ae25f0c
Removing intermediate container 7298ad7e902f
Step 2 : CMD java HelloWorld
---> Running in 0fa2151dc7b0
---> 25453e89b3f0
Removing intermediate container 0fa2151dc7b0
Successfully built 25453e89b3f0
但是,當我嘗試運行,它引發以下錯誤:
[[email protected] myjavadir]# docker run runhelloworld
exec: "/bin/sh": stat /bin/sh: no such file or directory
Error response from daemon: Cannot start container 676717677d3f1bf3b0b000d68b60c32826939b8c6ec1b5f2e9876969c60e22a4: [8] System error: exec: "/bin/sh": stat /bin/sh: no such file or directory
[[email protected] myjavadir]# exec: "/bin/sh": stat /bin/sh: no such file or directory
bash: exec:: command not found
請幫助解決一樣。
將第二行改爲RUN
後進行更新。
[[email protected] myjavadir]# docker build -t runhelloworld .
Sending build context to Docker daemon 3.584 kB
Sending build context to Docker daemon
Step 0 : FROM scratch
--->
Step 1 : RUN javac HelloWorld.java
---> Running in fdef2d65ac58
exec: "/bin/sh": stat /bin/sh: no such file or directory [8]
System error: exec: "/bin/sh": stat /bin/sh: no such file or directory
你可以嘗試從Java,而不是從頭開始,因爲它需要Java的依賴最小運行Java應用程序 –
http://stackoverflow.com/questions/31696439/how-to-build-a- docker-container-for-java-app/31710204#31710204 –