docker run with port-forward fails - java

This is my docker file
FROM openjdk:8-jre-slim
RUN mkdir /app
COPY dept-1.0.jar /app
CMD java -jar /app/dept-1.0.jar
EXPOSE 8080
The docker image can be run without any issues if I were to run like without port-forward
docker run --name=department dept:latest
But with port-forward docker run --name=department dept:latest -p 8082:8080 I see this error -
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"-p\": executable file not found in $PATH": unknown.
Can someone help pls ?

I changed the following in the Dockerfil
CMD java -jar /app/dept-1.0.jar
to
ENTRYPOINT ["java", "-jar", "/app/dept-1.0.jar"]
This solved my issue.

Related

Exception in thread "main" java.lang.UnsupportedClassVersionError Docker Compose

I have a microservice that is called account.query. When I try to up services by using docker compose up command, account.query is getting an error.
I have also a microservice that is called account.cmd, but it is not getting an error.
I have been trying to solve this problem for hours, but I could not.
Here is Docker file my account.query microservice.
FROM adoptopenjdk:11.0.4_11-jre-hotspot
EXPOSE 5003
RUN mkdir -p /usr/app
WORKDIR /usr/app
COPY build/libs/account.query-0.0.1-SNAPSHOT.jar /usr/app/
ENV JAVA_OPTS="-Xmx32m"
CMD exec java $JAVA_OPTS -jar account.query-0.0.1-SNAPSHOT.jar
Here is Docker logs for the service.
Here is my github repository.
https://github.com/dogaanismail/bank-solution
I would be very happy if someone could help.

Docker unable to access jar file without docker-compose

as far as I know I only got this answer for my query, but unfortunately I do not have docker-compose.yml I am just trying with plain Dockerfile below is my dockerFile.
FROM openjdk:8-jre-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} ebiPorjectJava.jar
ENTRYPOINT ["java","-jar","/ebiProjectJava.jar"]
but build is getting successful, by below command.
docker build -t ebiproject .
but when I am trying to run the docker it says unable to access jar file
docker run -p 3000:3000 ebiproejct
but it says unable to access jar
I am running docker on windows and I have spring boot application to run
I updated with below one:
FROM openjdk:8-jre-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} /ebiProjectJava.jar
ENTRYPOINT ["java","-jar","/ebiProjectJava.jar"]
but now I am getting corrupted error:
ARG JAR_FILE
expects you to pass the path of the jar_file as docker run argument
Otherwise nothing will be copied to the place, thus java jar won't be able to run the jar.
Check this out: https://vsupalov.com/docker-env-vars/
In this situation you can go in your container with this command:
docker run --rm -it <container_name> <image_name> <command>
you can use bash, ash or sh as
and after entering the container, you can check, run, or any tests in that.

When i try to run docker it says /bin/sh: [java,-jar,/bin/sh/hellotm-0.0.1-snapshort.jar]: not found

This is the error I get:
docker run -dit openjdk:8-jdk-alpine
docker images
docker container ls
docker container exec flamboyant_knuth ls /tmp
docker container cp target/HelloTm-0.0.1-SNAPSHOT.jar flamboyant_knuth:/tmp
docker container exec flamboyant_knuth ls /tmp
docker container commit flamboyant_knuth syedwn14/hellotm-0.0.1-snapshort:manual1
docker images
docker run syedwn14/hellotm-0.0.1-snapshort:manual1
docker container commit --change="CMD ["java","-jar","/tmp/hellotm-0.0.1-snapshort.jar"]" flamboyant_knuth syedwn14/hellotm-0.0.1-snapshort:manual2
docker run -p 8080:8080 syedwn14/hellotm-0.0.1-snapshort:manual2
Error:
/bin/sh: [java,-jar,/bin/sh/hellotm-0.0.1-snapshort.jar]: not found
Any help will be great.
I faced the same issue, was working on Windows.
Actual Problem
Running the following command docker container commit --change="CMD ["java","-jar","/tmp/hellotm-0.0.1-snapshort.jar"]" flamboyant_knuth syedwn14/hellotm-0.0.1-snapshort:manual2 from cmd or powershell adds Windows line endings (\r\n called CRLF).
On running the following command, the docker container is started.
docker run -p 8080:8080 syedwn14/hellotm-0.0.1-snapshort:manual2
Once the docker container has started it tries to execute the bash command.
["java","-jar","/tmp/hellotm-0.0.1-snapshort.jar"]
But instead throws an error
/bin/sh: [java,-jar,/bin/sh/hellotm-0.0.1-snapshort.jar]: not found.
For the bash command to be executed properly we need to convert the line endings of this command to Linux EOL (\n called "LF").
Easiest Solution that I use:
Install Git Bash (it provides a UNIX style command interface).
Run the following command from Git Bash docker container commit --change="CMD ["java","-jar","/tmp/hellotm-0.0.1-snapshort.jar"]" flamboyant_knuth syedwn14/hellotm-0.0.1-snapshort:manual2.
This will ensure that the line endings are Linux EOL.
Note: On running docker container exec flamboyant_knuth ls /tmp from Git Bash you will face the following error message.
$ docker container exec elated_fermat ls /tmp
ls: C:/Users/<user_name>/AppData/Local/Temp: No such file or directory
Instead run the command on either cmd or powershell.
Here's the Link to download Git Bash for Windows

Unable to access jarfile from docker run command for java maven project

Build docker images using docker file for maven project
When try running docker run getting error saying Unable to access jarfile.
Can some one assist on whats wrong with .
FROM openjdk:8-jre-alpine as release
RUN addgroup -g 1001 -S user1 && user1 -u 1001 -S user1 -G user1
WORKDIR /home/app
COPY --from=builder /home/app/service-1.0.0.jar .
RUN chown -R user1:user1 /home/app
USER user1
ENTRYPOINT ["java", "-jar" ,"/home/app/service-1.0.0.jar"]
but when i go for docker run with local config files as build mount
docker run -it --mount type=bind,source=D:/Java/service/docker/config,target=/home/app services
Unable to access jarfile /home/app/service-1.0.0.jar
Can someone assist on this or is something wrong i did??
I am not sure if you are looking for multistage docker build. If not, you need not use "COPY --from=builder" as it tires to copy the build artifact from your previous stage to this new stage. If it is a single stage docker build, you might just use the copy as follows -
COPY /home/app/service-1.0.0.jar .
Able to resolve the same, Issue was due to mound of config files not happened properly.
instead of docker run -it --mount type=bind,source=D:/Java/service/docker/config,target=/home/app services changes it to docker run -it --mount type=bind,source=D:/Java/service/docker/config/app.config,target=/home/app services which made service to load and work

Cannot run my Java 8 application from docker container

I can properly launch this Java 8 application using this command from a bash shell:
java -cp "simple-queue-0.1-SNAPSHOT.jar:jms-1.1.jar:commons-logging-1.2.jar:activemq-all-5.13.3.jar"
-Dserver1="my1.domain.com"
-Dserver2="my2.domain.com"
-Dusername="user"
-Dpassword="passwd"
com.fusesource.activemq.exercises.simple.queue.SimpleProducer
I want to containerize this application, so here is my Dockerfile:
FROM store/oracle/serverjre:8
MAINTAINER <me#myco.com>
EXPOSE 4567
VOLUME /data
COPY build/libs/*.jar /usr/local/bin/
COPY /app/simple-queue-0.1-SNAPSHOT.jar /usr/local/bin/
CMD ["java", "-cp", "/usr/local/bin/simple-queue-0.1-SNAPSHOT.jar:/usr/local/bin/jms-1.1.jar:/usr/local/bin/commons-logging-1.2.jar:/usr/local/bin/activemq-all-5.13.3.jar", "-Dserver1=$SERVER1", -Dserver2="$SERVER2", -Dusername="$USER", -Dpassword="$PASSWORD"]
I start my container like this:
docker run -it --rm -e SERVER1=my1.domain.com -e SERVER2=my2.domain.com -e USER=user -e PASSWORD=passwd ecosystem/simple-queue-client:1.1 com.fusesource.activemq.exercises.simple.queue.SimpleProducer
And I get this error message:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"com.fusesource.activemq.exercises.simple.queue.SimpleProducer\": executable file not found in $PATH": unknown.
When I get into that container, I can see that my jar files are in fact inside /usr/local/bin directory which is in the PATH. The CLASSPATH in the container is empty...
What do I need to do to fix this?
I used info from the link provided by midelb above and ended up with two containers: one for SimpleProducer and another for SimpleReceiver.
Here is the Docker file for one:
FROM store/oracle/serverjre:8
MAINTAINER <james.depaul#maxar.com>
VOLUME /data
COPY build/libs/*.jar /usr/local/bin/
COPY /app/simple-queue-0.1-SNAPSHOT.jar /usr/local/bin/
ENTRYPOINT java -classpath /usr/local/bin/simple-queue-0.1-SNAPSHOT.jar:/usr/local/bin/jms-1.1.jar:/usr/local/bin/commons-logging-1.2.jar:/usr/local/bin/activemq-all-5.13.3.jar -Dserver1=$SERVER1 -Dserver2=$SERVER2 -Dusername=$USER -Dpassword=$PASSWORD com.fusesource.activemq.exercises.simple.queue.SimpleConsumer
Build
docker build -t mysystem/simple-client-consumer:1.0
And I call it like this now:
docker run -d --rm -e SERVER1=server-b0.domain.com -e SERVER2=server-b1.domain.com -e USER=user -e PASSWORD=passwd mysystem/simple-client-consumer:1.0

Categories