This is using my Dockerfile
FROM lpicanco/java11-alpine
VOLUME /tmp
ADD knetconfig /tmp/knetconfig
ADD grpc_health_probe_linux_x64 /app/grpc_health_probe_linux_x64
RUN chmod +x /app/grpc_health_probe_linux_x64
ADD aero-pay-core-service-latest.jar app.jar
RUN sh -c 'touch /app.jar'
EXPOSE 5005
ENV JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Djava.security.egd=file:/dev/./urandom"
ENTRYPOINT java $JAVA_OPTS -jar /app.jar
But it getting this error in building time,I am using java 11,
Error occurred during initialization of VM
Could not find agent library jdwp on the library path, with error: libjdwp.so: cannot open shared object file: No such file or directory
What would be the best possible options?
It may be that the alpine version of JDK11 is tuned to minimize the footprint.
Likely a debugging library was removed or never installed.
Related
I was trying to extract dump.jar file then convert to csv file using this java command in ubuntu-docker (Linux platform) the code has no syntax error but there is no java, so it cannot process. How shall I call java from ubuntu inside the docker?
install Java but there is not enough space
ANY IDEA please?
trying
connect container with user root
docker exec -it -u root container_name /bin/bash
install java 11 or other version
apt-get install openjdk-11-jdk
java --version
now you can use java in docker container
I have java 13 installed on my machine and I have a project where I mentioned java 11 in the Dockerfile, so what should happen here is that when I build the docker image it should be built on top of java 11.
but surprisingly I get this error when running the container com/example/Application has been compiled by a more recent version of the Java Runtime.
The Dockerfile:
FROM openjdk:11.0.2-jdk
# Unpack distribution tar
ADD /distributions/application.tar /
RUN mkdir /src
RUN mkdir /src/main
RUN mkdir /src/main/resources
RUN mkdir /src/main/resources/ssl
ADD ./main/resources/ssl/keystore.p12 /src/main/resources/ssl/keystore.p12
# create JAR with unversioned name
RUN cp /application/lib/application-*.jar /application/lib/application.jar
ENTRYPOINT java -jar /application/lib/application.jar
Does anyone have an explanation for this?
You can use something similar to this:
FROM eclipse-temurin:16.0.2_7-jdk-centos7 AS builder
VOLUME /tmp
COPY . .
WORKDIR /
RUN ./gradlew assemble
FROM eclipse-temurin:16.0.2_7-jdk-centos7
WORKDIR /
COPY --from=builder build/libs build/libs
RUN ls -lah
RUN jar -xvf build/libs/*.jar
COPY build/libs/BOOT-INF/lib app/lib
COPY build/libs/META-INF/ app/META-INF
COPY build/libs/BOOT-INF/classes app/
RUN rm -rf build/libs
ENTRYPOINT ["java", "-cp", "app:app/lib/*", "com.example.springtest.SpringTestApplication"]
which effectively is a multi stage docker file that builds the image internally at the docker container. This means that your choice of Java version for building is locked down and does not get affected by what you run on your local machine. However, as mentioned before there are a few caveats here:
Developing against a newer Java version and then attempting to target an older one can lead to compatibility issues.
Always re-building the project in order to produce a Docker image can affect performance negatively (image what would happen if you were to run this at a CI level).
Thus based on all the above, I would suggest to align your development environment with what you are targeting as a deployment. This is turn would allow you to build the application locally and then simply proceed into copying the necessary artifacts/assets into the created container.
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...
Mac 10.10.5 here, using docker-machine to create a VirtualBox host VM for my local Docker. I have a project that builds an executable JVM located at build/libs/myapp-SNAPSHOT.jar. My Dockerfile, which is located in the root of the project, looks like:
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD build/libs/myapp-SNAPSHOT.jar myapp.jar
RUN sh -c 'touch /myapp.jar'
ENTRYPOINT ["java","-jar","/myapp.jar"]
Please note, I don't wish to push my images to any registry, just keep/run them locally (for now). When I run:
docker build -t myorg/myapp .
I get the following console output:
myuser#mymachine:~/sandbox/myapp$docker build -t myorg/myapp .
Sending build context to Docker daemon 42.69 MB
Step 1 : FROM frolvlad/alpine-oraclejdk8:slim
slim: Pulling from frolvlad/alpine-oraclejdk8
d0ca440e8637: Downloading [=================================================> ] 2.295 MB/2.32 MB
0f86278f6be1: Downloading [=================================================> ] 3.149 MB/3.172 MB
c704a6161dca: Download complete
And then the command-line just hangs after printing that "Download complete" message. I've waited for as long as 30 minutes (!!!) and nothing happens.
Any ideas where I'm going awry?
The VM is probably hanging. Try the following: https://github.com/docker/machine/issues/1819#issuecomment-138981139
docker-machine rm -f default
rm -fv ~/.docker/machine
docker-machine -D create -d virtualbox default
There are more issues about this on OSX.
I think the best practice is to setup a Linux native build box if you are doing any serious development. That way you can run docker without any VM overhead(which is ironically one of the major pain points docker is trying to solve)
There's also a Docker Beta program which runs on libcontainer natively on OSX and Windows.
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).