https://kotlinlang.org logo
#spring
Title
# spring
p

Pihentagy

03/17/2023, 2:15 PM
What's the simplest way to run a spring boot kotlin app inside docker? My attempt does not work, it freezes 😞
Copy code
docker run --user $(id -u) --volume "$PWD":/home/gradle/project --workdir /home/gradle/project gradle:7-jdk17 gradle --no-daemon --no-rebuild --no-scan --no-watch-fs --no-parallel bootRun
(to which channel does this question fit?)
t

thanksforallthefish

03/17/2023, 2:31 PM
bootJar
does packaging, you probably want
bootRun
instead
p

Pihentagy

03/17/2023, 2:34 PM
Ah, that's a real typo, but the effect is the same. (thanks, corrected)
t

thanksforallthefish

03/17/2023, 2:35 PM
or, you can create the image with
./gradlew bootBuildImage --imageName=myorg/myapp
and then run it with
docker run -p 8080:8080 -t myorg/myapp
🙏 1
👍 1
a

ashmelev

03/17/2023, 2:46 PM
Super simple to install and use. There's options for building the container straight to local Docker install or you can send the image to any of the cloud-based repositories (I use AWS ECR).
Lastly Jib is magical in a CI/CD pipeline because it does not actually require Docker to be installed. I've been using it for about 2 years and would not use anything else for container creation
One you install it in your build file (the Gradle plugin, I mean) it's just
./gradlew jubDockerBuild
and then just start the container - your SpringBoot app launches automatically and normally - no commands needed. Magic
p

Pihentagy

03/17/2023, 2:51 PM
How is it different from bootBuildImage suggested by @thanksforallthefish?
a

ashmelev

03/17/2023, 2:54 PM
Dunno, have not used bootBuildImage
According to the buildBootImage doc, "The
bootBuildImage
task requires access to a Docker daemon". Job does not require that - hence a CI/CD is simpler to set up
Other than that the two seem quite similar, the Gradle Jib config looks simpler to my eyes, but I've been using it for years, so I am biased
p

Pihentagy

03/17/2023, 3:00 PM
Thanks for both of you!
🙇 1
So, it works, but it is painfully slow btw.
a

ashmelev

03/17/2023, 3:14 PM
Which "it"?
p

Pihentagy

03/17/2023, 3:16 PM
./gradlew bootBuildImage, but seems like it is just the first time, when it pulls images from net.
a

ashmelev

03/17/2023, 3:28 PM
That and it's building "layers". Later image builds will only create the changed layers. Also, at least in my experience with Jib, pushing to cloud repos (ECR) is significantly faster as it pushes only the changed layers - very elegant
38 Views