Hallo, ich bin neu in Docker und versuche, ein neues Bild von Grund auf neu zu schreiben. Ich schreibe diese dockerFile, um ein einfaches Java-Programm zu kompilieren und auszuführen, das im selben Verzeichnis verfügbar ist.DockerFile zum Ausführen eines Java-Programms
Hier ist die Dockerfile.
FROM scratch
CMD javac HelloWorld.java
CMD java HelloWorld
Docker Build ist erfolgreich wie unter
[[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
gezeigt Aber wenn ich zu laufen versuchen, wirft es den folgenden Fehler:
[[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
Bitte helfen, das Gleiche zu lösen.
Aktualisierung nach der zweiten Zeile zu 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
Sie können aus Java versuchen, anstatt von Grund auf, weil es die minimale Abhängigkeit von Java benötigt eine Java-Anwendung auszuführen –
http://stackoverflow.com/questions/31696439/how-to-build-a- docker-container-fuer-ein-java-app/31710204 # 31710204 –