I am using GraalVM to create a native image of petclinic in Java SpringBoot
Here is my DockerFile
FROM oracle/graalvm-ce:19.2.1
WORKDIR /opt/graalvm
RUN gu install native-image
COPY ./spring-petclinic/* /usr/local/
RUN native-image -jar /usr/local/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar
FROM alpine:latest
WORKDIR /usr/local/
COPY --from=0 /opt/graalvm/spring-petclinic-2.2.0.BUILD-SNAPSHOT .
CMD yes
When I am using the image and do a ls -la I see the file spring-petclinic-2.2.0.BUILD-SNAPSHOT which is the native image I want to execute
My problem append when I try to execute de binary.
I get this error message:
sh: ./spring-petclinic-2.2.0.BUILD-SNAPSHOT: not found
I cannot execute a file which exists.
Related
I am trying to build docker image having following command in Dockerfile
FROM openjdk:13-jdk-alpine AS builder
WORKDIR /app-build
ADD . .
RUN pwd
RUN ./gradlew console:build
RUN ls /app-build/console/build/libs/
It exit with following message
/bin/sh: ./gradlew: not found
The command '/bin/sh -c ./gradlew console:build' returned a non-zero code: 127
you need to place your local directory path where your docker file is located and the path of your code repo in docker build command
docker build -f /home/ubuntu/your_project_repo/Dockerfile /home/ubuntu/your_project_repo/
I am not certain what openjdk:13-jdk-alpine already has in its image, but if does not already contain a ./gradlew executable file, you will need to double-check that the line ADD . . in your Dockerfile is actually copying in the file ./gradlew.
Is ./gradlew stored locally in the same path as your Dockerfile? ADD . . will take all the files in the path of your Dockerfile and copy it over into your custom image.
Another way to check to see if you are copying in the correct files is by building the image and then using a docker exec command to manually check to see what files are in your custom Docker image.
I would use the following command to do this: docker exec -it <name_of_docker_image> bash
How to pass the path of the script file to the CMD in the Dockerfile?
Here is my Dockerfile
FROM openjdk:8-jdk-alpine as base
EXPOSE 8080
WORKDIR '/app'
COPY run/ .
RUN mvn clean install
FROM openjdk:8-jdk-alpine
WORKDIR '/app'
COPY --from=base /app/data/startup.sh ./startup.sh
RUN ["chmod", "+x", "startup.sh"]
CMD ["startup.sh", "start"]
When I gave CMD ["/app/startup.sh", "start"], throws the below error
Cannot start service myapp: OCI runtime create failed:
container_linux.go:367: starting container process caused: exec: "/app/startup.sh": stat
/app/startup.sh: no such file or directory: unknown
The documentation says the path would be relative to the WORKDIR, so I tried passing the scriptname alone as it is now - CMD ["startup.sh", "start"] which resulted in the below error:
Cannot start service myapp: OCI runtime create failed:
container_linux.go:367: starting container process caused: exec: "service.sh": executable file
not found in $PATH: unknown
The startup.sh is a simple script file with a shebang - #!/bin/sh
Am I missing anything here? I am using docker desktop for windows and get the error when I run docker-compose up just fyi.
Please share how I can resolve this issue. Thanks
You are copying the file to /app/data in this step COPY --from=base /app/data/
So try:
CMD ["/app/data/startup.sh", "start"]
CMD ["/app/data/startup.sh", "start"]
should work
So I am trying to run a spring boot app with maven wrapper inside the docker container. Here is my Docker file:
### Stage 1: Build the application
FROM openjdk:8-jdk-alpine as build
RUN mkdir -p /app
#Set the current working directory inside the image
WORKDIR /app
#copy maven executable to the image
COPY mvnw .
COPY .mvn .mvn
#Copy the pom.xml file
COPY pom.xml .
#Build all the dependencies in preparation to go offline
#This is a separate step so the dependencies will be cached unless
#the pom.xml file has changed
RUN ./mvnw dependency:go-offline -B
#Copy the project source
COPY src src
#Package the application
RUN ./mvnw package -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)
I have this error:
Step 7/16 : RUN ./mvnw dependency:go-offline -B
---> Running in 642a32f86392
/bin/sh: ./mvnw: not found
ERROR: Service 'app-server' failed to build: The command '/bin/sh -c ./mvnw dependency:go-offline -B' returned a non-zero code: 127
I am working with windows 10 pro. Please I need your help
Maybe a duplicate of Unable to run './mvnw clean install' when building docker image based on "openjdk:8-jdk-alpine" for Spring Boot app
Can you check the line endings of the mvnw shell script?
You could fix it by adding this before executing the mvnw command:
RUN dos2unix mvnw
Alternatively, if the file is in git, you can also fix it by adding the following to a .gitattributes file and checking the file out again:
*.bat text eol=crlf
mvnw text eol=lf
You have to copy the project files into the /app dir first. And you don't have the maven wrapper in the context folder where you run the docker build.
Try change the end of line mvnw file from Windows style CRLF to Unix style LF. Then rebuild the image.
I'm trying to run my Java game in Docker, but when i try to run it i get this error message
Error: Invalid or corrupt jarfile /usr/src/app/v0.0.6 - FINAL.jar
Dockerfile
# Base image
FROM java:8
#COPY . /usr/src/app
#WORKDIR /usr/src/app
# Get Code v0.0.6 from Github
ADD ["https://github.com/JohnnyDeeee/Oils-Well/blob/master/Builds/v0.0.6/v0.0.6 - FINAL.jar", "/usr/src/app/"]
# DEBUG
RUN chmod +x "/usr/src/app/v0.0.6 - FINAL.jar"
RUN ls -al /usr/src/app
# Start the Game
CMD ["java", "-jar", "/usr/src/app/v0.0.6 - FINAL.jar"]
and this is how i build
docker build -t oilswell-v0.0.6 .
and run my image
docker run oilswell-v0.0.6
This is because of the way Github serves files, currently you are pulling this exact page from Github...
https://github.com/JohnnyDeeee/Oils-Well/blob/master/Builds/v0.0.6/v0.0.6%20-%20FINAL.jar
Which if you open it, you'll see it's not your JAR, but the page showing the JAR within the GIT repository. The URL you actually need is...
https://github.com/JohnnyDeeee/Oils-Well/blob/master/Builds/v0.0.6/v0.0.6%20-%20FINAL.jar?raw=true
This will return the actual JAR, rather than the HTML page. So your Dockerfile should look like this...
# Base image
FROM java:8
ADD ["https://github.com/JohnnyDeeee/Oils-Well/blob/master/Builds/v0.0.6/v0.0.6%20-%20FINAL.jar?raw=true", "/usr/src/app/"]
RUN chmod +x "/usr/src/app/v0.0.6 - FINAL.jar"
# Start the Game
CMD ["java", "-jar", "/usr/src/app/v0.0.6 - FINAL.jar"]
I am trying make a docker image of a java project. I first created a directory and in that I created a docker.txt file. The files contains this
FROM java:8
# Install maven
RUN apt-get update
RUN apt-get install -y maven
WORKDIR /home/mmt/CouchBaseClient/CB-RestAPI/CouchBaseThinClient
# Prepare by downloading dependencies
ADD pom.xml /home/mmt/CouchBaseClient/CB-RestAPI/CouchBaseThinClient/pom.xml
RUN ["mvn", "dependency:resolve"]
RUN ["mvn", "verify"]
# Adding source, compile and package into a fat jar
ADD src /home/mmt/CouchBaseClient/CB-RestAPI/CouchBaseThinClient/src
RUN ["mvn", "package"]
EXPOSE 4567
CMD ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "target/sparkexample-jar-with-dependencies.jar"]
and then I run in terminal the following command
docker build -t API .
I get the following error
invalid value "API" for flag -t: Error parsing reference: "API" is not a valid repository/tag
See 'docker build --help'.
Docker is complaining about "API" in the sense that it's not allowed to have a tag name with one or more character in uppercase:
$ docker build -t FOO .
repository name component must match "[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*"
Usually "recipes" to build Docker images are written in a file named Dockerfile, anyway you can continue to use docker.txt using the -f option:
docker build -f docker.txt -t api .