【发布时间】:2016-05-19 09:08:15
【问题描述】:
您好,我是 Docker 新手,正在尝试从头开始编写新镜像。我正在编写这个 dockerFile 来编译和运行同一目录中可用的简单 java 程序。
这里是 dockerfile。
FROM scratch
CMD javac HelloWorld.java
CMD java HelloWorld
Docker构建成功如下图
[root@hadoop01 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
但是当我尝试运行时,它会抛出以下错误:
[root@hadoop01 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
[root@hadoop01 myjavadir]# exec: "/bin/sh": stat /bin/sh: no such file or directory
bash: exec:: command not found
请帮忙解决。
将第二行更改为RUN 后更新。
[root@hadoop01 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
【问题讨论】:
-
你可以尝试FROM java而不是FROM scratch,因为它需要java的最小依赖来运行一个java应用程序