can not start java container with command in dockerfile - docker

I have an image that is built using this dockerfile.
# vi Dockerfile
FROM openjdk:8
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
I can login to container in interactive mode and type this command that works as expected.
java -jar /usr/src/myapp/dist/some.jar
But if I add this line to Dockerfile, I get an error:
CMD ["/usr/src/myapp/dist/some.jar", "java"]
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \" -jar /usr/src/myapp/dist/some.jar\": stat -jar /usr/src/myapp/dist/some.jar: no such file or directory".
How do I add the java command to dockerfile?

You are using thus wrongly. It should be
CMD ["java", "-jar", "/usr/src/myapp/dist/some.jar"]
or
CMD java -jar /usr/src/myapp/dist/some.jar

Why don't you use the same command as you would type in?
CMD ["java", "-jar", "/usr/src/myapp/dist/some.jar"]

Related

Where am I going wrong with my Dockerfile?

I've created a Dockerfile at the root of a directory that contains a web application. My Dockerfile reads as follows:
FROM openjdk:8u282-jre
MAINTAINER me <me#email.com>
COPY target/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar /
EXPOSE 8080
ENTRYPOINT ["java -jar"]
I'm attempting to copy a jar file from my local machine using the path from the within the root of the project directory - copying this to the root of the container, expose port 8080, and use an entry point thinking that after building the image, the jar will be run as an executable using this entry point. I then built the image as follows:
docker build -t se441/spring-petclinic:standalone .
Giving the build the name se441/spring-petclinic:standalone, I then attempt to run the container:
docker run -i -t se441/spring-petclinic:standalone
And I am getting the following error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370:
starting container process caused: exec: "java -jar": executable file not found in $PATH:
unknown.
I edited the Dockerfile to have the entry point be a /bin/bash, did an 'ls' and the jar file is definitely there. While in the container, I can run the jar successfully. Any advice on why the jar file can't be found when building/running with the Dockerfile as I've listed above. would be greatly appreciated. Thank you.
Change:
ENTRYPOINT ["java -jar"]
to:
ENTRYPOINT ["java", "-jar"]
The exec syntax (with the json array) does no do any command line parsing that you get with a shell, so it's looking for the literal binary java -jar rather than java and passing the -jar argument. You need to separate each parameter as another array entry, just as you'd separate them with spaces on the command line.
At that point, you'll find that -jar expects the name of the jar file. You can pass that as an argument when you run the container, e.g.:
docker run -i -t se441/spring-petclinic:standalone spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar
Or specify that as well in the entrypoint:
ENTRYPOINT ["java", "-jar", "spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar"]

Docker : OCI runtime create failed: executable file not found in $PATH

The error message I am getting while running the container:
Docker: Error response from daemon: OCI runtime create failed:
container_linux.go:348: starting container process caused "exec:
\"mkdir NNEEWW\": executable file not found in $PATH": unknown
My Dockerfile:
FROM python:3
COPY . /
RUN pip install --no-cache-dir -r /requirements.txt
EXPOSE 5678
CMD ["mkdir NNEEWW", "&", "jupyter", "notebook", "--ip=0.0.0.0",
"--port=5678", "--allow-root"]
You need to extract "mkdir NNEEWW", "&"* outside the CMD as in docker CMD is used to run the executable, you can anyway create a new folder before the CMD command if you need by using the command RUN mkdir NNEEWW.

Docker Run error with ENTRYPOINT

I am very new to Docker and I am able to successfully create an Image from Docker file but when I pulled it and ran a docker start on that it threw following error:
Error response from daemon: oci runtime error:
container_linux.go:247: starting container process caused "exec: \"./Myfolder\": stat ./Myfolder: no such file or directory".
The only place that I mentioned /Myfolder is in docker File ENTRYPOINT
as below ENTRYPOINT ["./Myfolder"]
While my Dockerfile looks like following:
FROM microsoft/dotnet:1.1.1-runtime
WORKDIR /opt/outputDirectory
ENTRYPOINT ["./Myfolder"]
COPY output /opt/outputDirectory
and this is assuming my entry point is the ENTRYPOINT project's directory name (the one containing /bin) what could I be missing?
ENTRYPOINT specify the program that runs inside the container. You've put a directory.
See this example:
FROM microsoft/dotnet:1.0-runtime
WORKDIR /app
COPY out ./
ENTRYPOINT ["dotnet", "dotnetapp.dll"]

Docker Image can't execute command

My Dockerfile looks like below:
FROM scratch
RUN skype
I have skype installed in my OS and when I try to build the docker with below command:
sudo docker build -t tryskyped .
It says
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM scratch
--->
Step 2/2 : RUN skype
---> Running in 0ecf7c719567
container_linux.go:247: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"
oci runtime error: container_linux.go:247: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"
If I am not wrong it should have executed like /bin/sh -c skype. When I manually try this , I can see the skype opens
I am very new to this and I am just trying out docker.Please help
Your Dockerfile does nothing, as it does not have a CMD or ENTRYPOINT to execute.
A Dockerfile has a configuration phase (the RUN, ADD, COPY and so) and a start phase, with ENTRYPOINT and CMD
As an example, the last line of the Dockerfile for the Nginx image reference contains
extract from
https://github.com/nginxinc/docker-nginx/blob/0c7611139f2ce7c5a6b1febbfd5b436c8c7d2d53/mainline/jessie/Dockerfile
CMD ["nginx", "-g", "daemon off;"]
Check What is the difference between CMD and ENTRYPOINT in a Dockerfile?
The doc for CMD
https://docs.docker.com/engine/reference/builder/#cmd
for ENTRYPOINT
https://docs.docker.com/engine/reference/builder/#entrypoint

Docker run java app

I have a simple hello world java app and I want to build Docker image which runs it.
Dockerfile:
FROM java:8
ADD dist/JavaApplication1.jar /JavaApplication1.jar
RUN chmod +x /JavaApplication1.jar
CMD ["/usr/bin/java -jar /JavaApplication1.jar"] # or CMD ["java -jar /JavaApplication1.jar"]
I build it by:
docker build -t myapp .
And run it by:
docker run -tdi myapp
but it throws:
Error response from daemon: Cannot start container 105f043e565e465639e15d78e92dc74e64562faa510fae5d6ff48da3a58c0125: [8] System error: exec: "java -jar /JavaApplication1.jar": stat java -jar /JavaApplication1.jar: no such file or directory
When run it by:
docker run -ti myapp bash
and do ls, the file is there and when I run "/usr/bin/java -jar /JavaApplication1.jar" then everything is ok. Where is problem?
My docker version: 1.9.0.
On docker 1.9.1 either of your approaches works for me:
exec: "/usr/bin/java -jar /JavaApplication1.jar": stat /usr/bin/java -jar /JavaApplication1.jar: no such file or directory
And that is consistent with documentation for CMD
Basically you can use:
CMD ["executable","param1","param2"]
CMD ["param1","param2"]
CMD command param1 param2
That would suggest first arg is a binary not a whole cmd, and that's the reason of your error. If you split up cmd as on example above that it will work just fine.
FROM java:8
ADD dist/JavaApplication1.jar /JavaApplication1.jar
CMD ["java", "-jar", "/JavaApplication1.jar"]
Bonus: chmod +x is not needed

Resources