why docker reports no such file or directory : unknown

user2315104 :

what is expected

docker should build the image and run the container out of it

Dockerfile

FROM centos:7

ENV JAVA_VERSION 8u191
ENV BUILD_VERSION b12

RUN yum -y install wget; wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/$JAVA_VERSION-$BUILD_VERSION/2787e4a523244c269598db4e85c51e0c/jdk-$JAVA_VERSION-linux-x64.rpm" -O /tmp/jdk-8-linux-x64.rpm; yum -y install /tmp/jdk-8-linux-x64.rpm

# JDK stripping
RUN rm -f /usr/java/jdk1.8.0_77/src.zip /usr/java/jdk1.8.0_77/javafx-src.zip
RUN rm -rf /usr/java/jdk1.8.0_77/lib/missioncontrol/ /usr/java/jdk1.8.0_77/lib/visualvm/ /usr/java/jdk1.8.0_77/db/

RUN alternatives --install /usr/bin/java java /usr/java/latest/bin/java 1
RUN alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 1

ENV JAVA_HOME /usr/java/latest
ENV PATH=$PATH:/usr/java/latest/bin/java
RUN echo "$PATH"

RUN rm -f /tmp/jdk-8-linux-x64.rpm; yum -y remove wget; yum -y clean all

COPY target/gs-handling-form-submission-0.1.0.jar /tmp/gs-handling-form-submission-0.1.0.jar

CMD [ "java -jar /tmp/gs-handling-form-submission-0.1.0.jar" ]

build-context is the current directory where Dockerfile resides. following is the directory structure

total 8
-rw-r--r--. 1 root     root     1079 Oct 29 03:42 Dockerfile
-rw-rw-r--. 1 ec2-user ec2-user 1917 Oct 27 09:17 pom.xml
drwxrwxr-x. 4 ec2-user ec2-user   30 Oct 27 10:15 src
drwxr-xr-x. 9 root     root      261 Oct 27 10:19 target

i am executing following command to build the image :

docker build --no-cache -f Dockerfile -t cpa:latest .

but when running the container , getting following message

docker run -d -p 8081:8081/tcp cpa   
b2ba9831f1b74c73669843658727ca0d64fcd9de915739b96e17dcfd6e63c7db
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"java -jar /tmp/gs-handling-form-submission-0.1.0.jar\": stat java -jar /tmp/gs-handling-form-submission-0.1.0.jar: no such file or directory": unknown.

I am not sure why the built jar is not available in the /tmp dir of the container file system in the docker documentation COPY is the right keyword to be used to copy files from host machine to container file system ... but then where is the issue ..? please suggest

EDIT 1 : fixed the type mistake from 77 to 191 here is the latest Dockerfile....

FROM centos:7

ENV JAVA_VERSION 8u191
ENV BUILD_VERSION b12

RUN yum -y install wget; wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/$JAVA_VERSION-$BUILD_VERSION/2787e4a523244c269598db4e85c51e0c/jdk-$JAVA_VERSION-linux-x64.rpm" -O /tmp/jdk-8-linux-x64.rpm; yum -y install /tmp/jdk-8-linux-x64.rpm

# JDK stripping
RUN rm -f /usr/java/jdk1.8.0_191/src.zip /usr/java/jdk1.8.0_191/javafx-src.zip
RUN rm -rf /usr/java/jdk1.8.0_191/lib/missioncontrol/ /usr/java/jdk1.8.0_191/lib/visualvm/ /usr/java/jdk1.8.0_191/db/

RUN alternatives --install /usr/bin/java java /usr/java/latest/bin/java 1
RUN alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 1

ENV JAVA_HOME /usr/java/latest
ENV PATH=$PATH:/usr/java/latest/bin/java
RUN echo "$PATH"

RUN rm -f /tmp/jdk-8-linux-x64.rpm; yum -y remove wget; yum -y clean all

COPY target/gs-handling-form-submission-0.1.0.jar /tmp/gs-handling-form-submission-0.1.0.jar

CMD [ "java -jar /tmp/gs-handling-form-submission-0.1.0.jar" ]

further, the target dir is part of the build context please refer below:

[root@ip-172-31-14-242 cpa_final]# pwd
/tmp/cpa_final
[root@ip-172-31-14-242 cpa_final]# ll
total 8
-rw-r--r--. 1 root     root     1084 Oct 29 05:16 Dockerfile
-rw-rw-r--. 1 ec2-user ec2-user 1917 Oct 27 09:17 pom.xml
drwxrwxr-x. 4 ec2-user ec2-user   30 Oct 27 10:15 src
drwxr-xr-x. 9 root     root      261 Oct 27 10:19 target
[root@ip-172-31-14-242 cpa_final]# cd target/
[root@ip-172-31-14-242 target]# ll
total 17304
drwxr-xr-x. 4 root root       36 Oct 27 10:18 classes
drwxr-xr-x. 3 root root       25 Oct 27 10:18 generated-sources
drwxr-xr-x. 3 root root       30 Oct 27 10:18 generated-test-sources
-rw-r--r--. 1 root root 17708542 Oct 27 10:19 gs-handling-form-submission-0.1.0.jar
-rw-r--r--. 1 root root     4858 Oct 27 10:18 gs-handling-form-submission-0.1.0.jar.original
drwxr-xr-x. 2 root root       28 Oct 27 10:18 maven-archiver
drwxr-xr-x. 3 root root       35 Oct 27 10:18 maven-status
drwxr-xr-x. 2 root root      121 Oct 27 10:18 surefire-reports
drwxr-xr-x. 3 root root       19 Oct 27 10:18 test-classes
[root@ip-172-31-14-242 target]#

EDIT 2:

the mentioned jar file is there in /tmp dir of the container file system. PSB

[root@ip-172-31-14-242 ~]# docker run -it cpa /bin/bash
[root@4018a6c2df8e /]# cd /tmp
[root@4018a6c2df8e tmp]# ll
total 17300
-rw-r--r--. 1 root root 17708542 Oct 27 10:19 gs-handling-form-submission-0.1.0.jar
-rwx------. 1 root root      836 Oct  6 19:15 ks-script-7RxiSx
-rw-------. 1 root root        0 Oct  6 19:14 yum.log
[root@4018a6c2df8e tmp]#
kutschkem :
ENV PATH=$PATH:/usr/java/latest/bin/java

should probably be

ENV PATH=$PATH:/usr/java/latest/bin

I assume what is not being found is the java executable. Please check that java is really on the PATH.

What is ALSO wrong is this line:

CMD [ "java -jar /tmp/gs-handling-form-submission-0.1.0.jar" ]

This should read:

CMD [ "java", "-jar", "/tmp/gs-handling-form-submission-0.1.0.jar" ]

Right now it is looking for a file called "java -jar /tmp/gs-handling-form-submission-0.1.0.jar" and tries to execute that.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=90956&siteId=1