How to Docker with Spring Boot
This quick and easy tutorial shows you how to build Docker images with Spring Boot’s built-in Buildpacks support.
How to Docker with Spring Boot
This quick and easy tutorial shows you how to build Docker images with Spring Boot’s built-in Buildpacks support.
Maurizio Casciano
How can I deploy this Docker image on Heroku?
https://stackoverflow.com/q…
Matt Raible
Hello Maurizio,
I just tried deploying the Docker container created in this post:
heroku container:login
docker tag springbootdemo registry.heroku.com/radiant-earth-48726/web
docker push registry.heroku.com/radiant-earth-48726/web
heroku container:release web
heroku logs --tail
You are correct in that it doesn’t start.
2020-12-29T13:26:26.863718+00:00 app[api]: Scaled to web@1:Free by user matt@raibledesigns.com
2020-12-29T13:26:33.551084+00:00 heroku[web.1]: Starting process with command/cnb/process/web
2020-12-29T13:26:36.710208+00:00 app[web.1]: Setting Active Processor Count to 8
2020-12-29T13:26:37.209651+00:00 app[web.1]: unable to calculate memory configuration
2020-12-29T13:26:37.209680+00:00 app[web.1]: fixed memory regions require 604289K which is greater than 512M available for allocation: -XX:MaxDirectMemorySize=10M, -XX:MaxMetaspaceSize=92289K, -XX:ReservedCodeCacheSize=240M, -Xss1M * 250 threads
2020-12-29T13:26:37.314632+00:00 heroku[web.1]: Process exited with status 1
2020-12-29T13:26:37.378646+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-29T13:26:37.383670+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-29T13:26:45.433241+00:00 heroku[web.1]: Starting process with command/cnb/process/web
2020-12-29T13:26:48.651953+00:00 app[web.1]: Setting Active Processor Count to 8
2020-12-29T13:26:49.202340+00:00 app[web.1]: unable to calculate memory configuration
2020-12-29T13:26:49.202378+00:00 app[web.1]: fixed memory regions require 604289K which is greater than 512M available for allocation: -XX:MaxDirectMemorySize=10M, -XX:MaxMetaspaceSize=92289K, -XX:ReservedCodeCacheSize=240M, -Xss1M * 250 threads
2020-12-29T13:26:49.304329+00:00 heroku[web.1]: Process exited with status 1
2020-12-29T13:26:49.361250+00:00 heroku[web.1]: State changed from starting to crashed
I’ll talk to some folks I know at Heroku and get back to you.
Matt Raible
I asked my friend, Joe Kutner, for his advice. He said the Paketo buildpacks refuse to allocate heap on containers smaller than 1GB of RAM. A free Heroku dyno has 512MB. You need to use the Heroku Buildpacks to solve this.
To fix:
1. Add server.port=${PORT:8080}
to your application.properties
2. Build using Heroku’s Buildpacks:
./gradlew bootBuildImage --imageName=springbootdemo --builder heroku/spring-boot-buildpacks
Here’s a PR to document these instructions in this example’s README.
You’ll need to update your Okta OIDC app to have your Heroku app’s redirect URIs as well.
Maurizio Casciano
Good to know, thanks Matt.
Maurizio Casciano
Hi @mattraible, I am trying to build the Docker image with Maven and the Heroku Buildpacks
<properties>
<java.version>15</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-maven-plugin</artifactid>
<configuration>
<image>
<name>my-image</name>
</image>
<imagebuilder>heroku/spring-boot-buildpacks</imagebuilder>
</configuration>
</plugin>
</plugins>
</build>
but I get
[INFO] > Running creator
[INFO] [creator] —> DETECTING
[INFO] [creator] heroku/jvm 0.1
[INFO] [creator] heroku/spring-boot 0.1
[INFO] [creator] —> ANALYZING
[INFO] [creator] Previous image with name “docker.io/my-image:latest” not found
[INFO] [creator] —> RESTORING
[INFO] [creator] —> BUILDING
[INFO] [creator]
[INFO] [creator] [Installing Java]
[INFO] [creator] /cnb/buildpacks/heroku_jvm/0.1/lib/jvm.sh: line 93: jdkUrl: unbound variable
[INFO] [creator] ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17:55 min
[INFO] Finished at: 2020-12-30T15:36:10+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.0:build-image (default-cli) on project server: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.0:build-image failed: Builder lifecycle ‘creator’ failed with status code 7 → [Help 1]
Do you know how can I fix this unbounded jdkUrl?
Matt Raible
I tried Java 15 with Gradle and the same error happens. To help diagnose your issue, I created a new project with Maven.
curl https://start.spring.io/starter.tgz -d dependencies=web,okta <br> -d bootVersion=2.4.1 <br> -d groupId=com.okta <br> -d artifactId=demospringboot <br> -d language=kotlin <br> -d baseDir=docker-maven-demo | tar -xzvf -
Then, I tried building it with the command below:
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=springbootdemo -Dspring-boot.build-image.builder=heroku/spring-boot-buildpacks
I see the same error:
[INFO] [creator] [Installing Java]
[INFO] [creator] /cnb/buildpacks/heroku_jvm/0.1/lib/jvm.sh: line 93: jdkUrl: unbound variable
[INFO] [creator] ERROR: failed to build: exit status 1
If I change the Java version to 11 in pom.xml
(or build.gradle.kts
), it works.
Matt Raible
Hello @mauriziocasciano! I mentioned this issue to the folks that work on the Heroku Buildpacks and they fixed it. Can you try again? It works for me with Java 15 now.
[INFO] — spring-boot-maven-plugin:2.4.1:build-image (default-cli) @ demospringboot —
[INFO] Building image ‘docker.io/library/springbootdemo:latest’
[INFO]
[INFO] > Pulling builder image ‘docker.io/heroku/spring-boot-buildpacks:latest’ 100%
[INFO] > Pulled builder image ‘heroku/spring-boot-buildpacks@sha256:730e3dc2ee4a0ecd05813510111f1e6deffc60a65bb602e393dc5f4b9d1d13b8’
[INFO] > Pulling run image ‘docker.io/heroku/pack:18’ 100%
[INFO] > Pulled run image ‘heroku/pack@sha256:88d516778df13c17c8749a0fa1102a4233d0cb97d25f790b27107da335c80781’
[INFO] > Executing lifecycle version v0.10.1
[INFO] > Using build cache volume ‘pack-cache-db4d6efc6a3f.build’
[INFO]
[INFO] > Running creator
[INFO] [creator] ===> DETECTING
[INFO] [creator] Warning: Warning: buildpack heroku/jvm has a “version” key. This key is deprecated in build plan requirements in buildpack API 0.3. “metadata.version” should be used instead
[INFO] [creator] heroku/jvm 0.1.0
[INFO] [creator] heroku/spring-boot 0.2.2
[INFO] [creator] ===> ANALYZING
[INFO] [creator] Restoring metadata for “heroku/jvm:jre” from app image
[INFO] [creator] Restoring metadata for “heroku/jvm:utils” from cache
[INFO] [creator] Restoring metadata for “heroku/jvm:jdk” from cache
[INFO] [creator] ===> RESTORING
[INFO] [creator] Restoring data for “heroku/jvm:jdk” from cache
[INFO] [creator] Restoring data for “heroku/jvm:utils” from cache
[INFO] [creator] ===> BUILDING
[INFO] [creator]
[INFO] [creator] [Installing Java]
[INFO] [creator] JDK 15 installed from cache
[INFO] [creator] JRE 15 installed from cache
[INFO] [creator] ===> EXPORTING
[INFO] [creator] Reusing layer ‘heroku/jvm:jre’
[INFO] [creator] Adding 1/1 app layer(s)
[INFO] [creator] Reusing layer ‘launcher’
[INFO] [creator] Adding layer ‘config’
[INFO] [creator] Reusing layer ‘process-types’
[INFO] [creator] Adding label ‘io.buildpacks.lifecycle.metadata’
[INFO] [creator] Adding label ‘io.buildpacks.build.metadata’
[INFO] [creator] Adding label ‘io.buildpacks.project.metadata’
[INFO] [creator] Setting default process type ‘web’
[INFO] [creator] *** Images (7af6d4a3d06e):
[INFO] [creator] docker.io/library/springbootdemo:latest
[INFO] [creator] Reusing cache layer ‘heroku/jvm:jdk’
[INFO] [creator] Reusing cache layer ‘heroku/jvm:utils’
[INFO]
[INFO] Successfully built image ‘docker.io/library/springbootdemo:latest’
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Maurizio Casciano
I can confirm that now it is working fine! Thanks once again @mattraible