JavaFX Docker Unable to open DISPLAY - java

I am trying to start a Java program in a docker container. After docker-compose build i try to start the program with docker-compose up but get the following error:
Exception in thread "main" java.lang.UnsupportedOperationException: Unable to open DISPLAY
The readme of the progam says:
"If you get the error message that the container cannot connect to Xorg (Unable to open DISPLAY) when starting the container, the supplied script "./startup.sh" needs to be executed".
startup.sh:
#!/bin/sh
xhost +local:
docker-compose up
xhost -local:
dockerfile
FROM ubuntu:16.04
RUN apt-get update && apt-get install --assume-yes --no-install-recommends openjfx openjdk-8-jdk maven git
COPY . /opt/Testfolder
WORKDIR /opt/Testfolder/src
RUN mvn package -DskipTests -Dcheckstyle.skip
CMD java -jar program.jar
At what point would i need to execute the startup.sh script? Do i need to add another RUN startup.sh in the dockerfile? Anyone has an idea?

Related

unable to start container process: exec: "mvnw": executable file not found in $PATH: unknown

This is my source code https://github.com/donhuvy/springboot-docker . I follow guide at tutorial video https://www.youtube.com/watch?v=7BCtc9cAS6o . File Dockerfile
# syntax=docker/dockerfile:1
#Which "official Java image" ?
FROM openjdk:oraclelinux8
#working directory
WORKDIR /app
#copy from your Host(PC, laptop) to container
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
#Run this inside the image
RUN ./mvnw dependency:go-offline
COPY src ./src
#run inside container
CMD [ "mvnw", "spring-boot:run" ]
Log
C:\Users\donhu>docker pull donhuvy/springboot-docker:v1.0.0
v1.0.0: Pulling from donhuvy/springboot-docker
e54b73e95ef3: Pull complete
e6e62647f09f: Pull complete
da8e06a8884e: Pull complete
d8cbf9b4e6de: Pull complete
9971eb650313: Pull complete
366b24bf882f: Pull complete
35b5c085babf: Pull complete
b51a76bbfa65: Pull complete
Digest: sha256:f637c16c3b2a930d048e95f89f2a7aa53754f349e08e0c5a86398c5481eb07f1
Status: Downloaded newer image for donhuvy/springboot-docker:v1.0.0
docker.io/donhuvy/springboot-docker:v1.0.0
C:\Users\donhu>docker run donhuvy/springboot-docker:v1.0.0
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "mvnw": executable file not found in $PATH: unknown.
C:\Users\donhu>
How to fix it?
add springboot-docker dir to your $PATH variable.
basically the shell is not able to find the mvnw command, it looks for all the locations in the $PATH var. since your mvnw binary is located in your project dir you need to add it.
if this was in a linux environment it would be done like this
export PATH=$PATH:./springboot-docker
for windows you can search online how this can be edited.
Change CMD [ "mvnw", "spring-boot:run" ] to CMD [ "./mvnw", "spring-boot:run" ]
When your docker want to execute command mvnw springboot:run, it needs to find file mvnw in environment $PATH, but find none.
Change mvnw to ./mvnw which will tell docker to execute the mvnw file in current work directory(where you have copied mvnw before).
it's a permission problem, common on linux docker compose.
In my case it worked when I REMOVED sudo.
i.e
docker-compose up instead of sudo docker-compose up
you can also try adding sudo chmod -R a+rwx to the working directory in Dockerfile

Docker | Unable to Access jarfile?

i want to build a minecraft spigot minecraft server with docker.
So i get in touch with docker and i dont think i get the entire hang of it.
When i run the image as a cotainer i get:
Recreating minecraft-spigot-1165x86_64_mc_1 ... done
Attaching to minecraft-spigot-1165x86_64_mc_1
mc_1 | Error: Unable to access jarfile spigot.jar
minecraft-spigot-1165x86_64_mc_1 exited with code 1
I dont know why it cant start the jar file. I already tried using "Entrypoint" and "CMD". Both dosent work :/. I added "RUN ls" so i can see if its copied, and yes its showing the file when i build the image. pls help :)
Used Dockerfile
FROM ubuntu:latest
LABEL maintainer="CruZer606#private"
RUN apt-get update && apt-get upgrade -y
RUN apt install default-jdk -y
RUN mkdir /srv/minecraft && cd /srv/minecraft
COPY spigot.jar /srv/minecraft/spigot.jar
WORKDIR /srv/minecraft
RUN ls -al
RUN echo "eula = true" > /srv/minecraft/eula.txt
EXPOSE 25565
ENTRYPOINT ["java", "-Xms4096M", "-Xmx4096M", "-jar", "spigot.jar"]

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

How to run a jar file from the open jdk docker image

I am trying to containerise an application using docker and the official openjdk image. From GitHub: https://github.com/jactor-rises/jactor-persistence/tree/feature-docker
I am trying to simulate the following jar command:
java -jar target/jactor-persistence-1.2.1-SNAPSHOT-app.jar
My Dockerfile:
FROM openjdk:13
LABEL jactor-rises="https://github.com/jactor-rises" \
email="..."
COPY target/jactor-persistence-*-app.jar /usr/src/myapp/app.jar
WORKDIR /usr/src/myapp
EXPOSE 1099
CMD [ "java -jar app.jar" ]
The application runs fine by changing the CMD line suggested by David Maze in his comment
CMD java -jar app.jar
No build error throw me off and I did not consider that this was a possible cause of the error...

Installing and using Gradle in a docker image/container

I am getting this strange error at the end of the process of creating a docker image from a Dockerfile:
/bin/sh: 1: gradle: not found
INFO[0003] The command [/bin/sh -c gradle test jar] returned a non-zero code: 127
The relevant part of the Dockerfile:
FROM debian:jessie
[...]
RUN curl -L https://services.gradle.org/distributions/gradle-2.4-bin.zip -o gradle-2.4-bin.zip
RUN apt-get install -y unzip
RUN unzip gradle-2.4-bin.zip
RUN echo 'export GRADLE_HOME=/app/gradle-2.4' >> $HOME/.bashrc
RUN echo 'export PATH=$PATH:$GRADLE_HOME/bin' >> $HOME/.bashrc
RUN /bin/bash -c "source $HOME/.bashrc"
RUN gradle test jar
[...]
The command I am using is: docker build -t java_i .
The strange thing is that if:
I run a container from the previous image commenting out RUN gradle test jar (command: docker run -d -p 9093:8080 -p 9094:8081 --name java_c -i -t java_i),
then I log into that container (command: docker exec -it java_c bash),
then I manually check the gradle environment variables finding them,
then I manually run that commented out command from within the running container (gradle test jar):
I eventually get the expected output (the compiled java code in the build folder).
I am using Docker version 1.6.2
I solved the problem using the ENV docker instructions (link to the documentation).
ENV GRADLE_HOME=/app/gradle-2.4
ENV PATH=$PATH:$GRADLE_HOME/bin
This command /bin/bash -c "source $HOME/.bashrc" means that you create a new non-interactive process and run a command in it to set environment variables there. Which does not affect the parent process. As soon as variables are set, process exits. You can check this by running something like this:
RUN /bin/bash -c "source $HOME/.bashrc; env"
RUN env
What should be working is this option:
RUN source ~/.bashrc
And the reason why it works when you log in, is because the new process reads already updated ~/.bashrc.
I was trying to install same version with JDK 11.0.7 but gradle-2.4 does not work. and got below error
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.7'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I install later version to fix the above issue after installation.
Posting as an answer might help someone else.
FROM openjdk:11.0.7-jdk
RUN apt-get update && apt-get install -y unzip
WORKDIR /gradle
RUN curl -L https://services.gradle.org/distributions/gradle-6.5.1-bin.zip -o gradle-6.5.1-bin.zip
RUN unzip gradle-6.5.1-bin.zip
ENV GRADLE_HOME=/gradle/gradle-6.5.1
ENV PATH=$PATH:$GRADLE_HOME/bin
RUN gradle --version
You can use multi-stage builds and the Gradle Docker image (no need to install Gradle...) to build the application then use the result in the runtime container:
# Build
FROM gradle AS build
WORKDIR /appbuild
COPY . /appbuild
RUN gradle --version
# here goes your build code
Once the Gradle build is done, switch to the runtime container:
# Runtime
FROM openjdk:8-jre-alpine
# more stuff here...
COPY --from=0 appbuild/<somepath>/some.jar application.jar
# more stuff here...
The COPY command copies the build artifacts from the build phase to the runtime container (in this case a jar file).

Categories