Cannot add jars to new Docker image using gradle-docker-plugin
As @nlloyd's comment, the key to the problem was my Dockerfile setting.
The following is the key part in my Gradle script with the problem.
...docker { name "${project.group}/${jar.baseName}" files jar.archivePath buildArgs(['JAR_FILE': "${jar.archiveName}"])}bootJar { baseName = 'gs-spring-boot-docker' version = '0.1.0'}...
It creates the jar file as follows:
.../build/libs/gs-spring-boot-docker-0.1.0.jar
and the following is the Dockerfile:
FROM openjdk:8-jdk-alpineVOLUME /tmpARG JAR_FILEADD ${JAR_FILE} app.jarENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
It takes an argument, 'JAR_FILE' that is supposed to be the full path of the jar file to be included in the new Docker image to be built and the specific value of JAR_FILE is specified by the docker task in the Gradle script through '${jar.archiveName}'.
The following is the error message I got during docker task.
ADD failed: stat /var/lib/docker/tmp/docker-builder498743832/gs-spring-boot-docker.jar: no such file or directory
It attempts to add '.../gs-spring-boot-docker.jar', but the actual name of the jar file is 'gs-spring-boot-docker-0.1.0.jar', followed by the version signature.
so I've removed the 'version' in bootJar in the Gradle script:
bootJar { baseName = 'gs-spring-boot-docker'}
Then it creates a jar file with the correct name, 'gs-spring-boot-docker.jar' and the build process is successfully completed.
I don't know yet there is a better way of doing this, but the problem is done.