My Spring boot application has a property file with AWS credentials, when I run gradle bootJar, the fat jar with all dependencies is built and I can run it with java -jar
But when I bundle I build a Docker image, what I get is the following error, basically complaining that it can't find AWS credentials in the property file under resources
2021-03-23 17:51:01.542 ERROR 1 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)), SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey), WebIdentityTokenCredentialsProvider: To use assume role profiles the aws-java-sdk-sts module must be on the class path., com.amazonaws.auth.profile.ProfileCredentialsProvider@61a02480: profile file cannot be null, com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@23b9c9f8: Failed to connect to service endpoint: ]] with root cause
Note again that the I can run the assembled fat jar with java -jar that has the same credentials property file with no issues.
This is my Dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.myapp.myapp"]
And these are the docker tasks in build.gradle (after of course importing palantir) to build the image
apply plugin: 'com.palantir.docker'
group = 'com.myapp'
bootJar {
baseName = 'mayapp'
version = '0.1.0'
}
task unpack(type: Copy) {
dependsOn bootJar
from(zipTree(tasks.bootJar.outputs.files.singleFile))
into("build/dependency")
}
docker {
name "${project.group}/${bootJar.baseName}"
copySpec.from(tasks.unpack.outputs).into("dependency")
buildArgs(['DEPENDENCY': "dependency"])
}
and this is how I run the container
docker run -p 8080:8080 com.myapp/myapp
Should be ENTRYPOINT ["java","-cp","/app:/app/lib/*","com.myapp.myapp"]
Not sure how your classpath was found with app:app/lib/*
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.