2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Gradle×springbootアプリケーションをdockerイメージ化してコンテナ起動する

Posted at

結論

./gradlew bootBuildImage

docker run -it -p 8888:8888 sample-rest-controller:0.0.1

説明

./gradlew bootBuildImage --imageName={イメージ名}:{バージョン(X.X.X)}でイメージ作成可能。とってもかんたん。
(少し時間かかる場合がある)

./gradlew bootBuildImage --imageName=sample-rest-controller:0.0.1

(略)

Successfully built image 'docker.io/library/sample-rest-controller:0.0.1'


BUILD SUCCESSFUL in 3m 33s
5 actionable tasks: 3 executed, 2 up-to-date

docker image lsすると、作成されたイメージが確認できる。

docker image ls
REPOSITORY                      TAG        IMAGE ID       CREATED        SIZE
sample-rest-controller          0.0.1      f6e62c028ea8   43 years ago   277MB

コンテナ起動してみる。

docker run -it -p 8888:8888 sample-rest-controller:0.0.1

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Setting Active Processor Count to 4
Calculating JVM memory based on 3117676K available memory
For more information on this calculation, see https://paketo.io/docs/reference/java-reference/#memory-calculator
Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx2732403K -XX:MaxMetaspaceSize=78072K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 3117676K, Thread Count: 50, Loaded Class Count: 11370, Headroom: 0%)
Enabling Java Native Memory Tracking
Adding 124 container CA certificates to JVM truststore
Spring Cloud Bindings Enabled
Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -XX:+ExitOnOutOfMemoryError -XX:ActiveProcessorCount=4 -XX:MaxDirectMemorySize=10M -Xmx2732403K -XX:MaxMetaspaceSize=78072K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.1)

2022-12-31T10:19:34.329Z  INFO 1 --- [           main] c.e.s.SampleRestApiApplication           : Starting SampleRestApiApplication using Java 17.0.5 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
2022-12-31T10:19:34.344Z  INFO 1 --- [           main] c.e.s.SampleRestApiApplication           : No active profile set, falling back to 1 default profile: "default"
2022-12-31T10:19:40.891Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
2022-12-31T10:19:40.933Z  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-12-31T10:19:40.934Z  INFO 1 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.4]
2022-12-31T10:19:41.286Z  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-12-31T10:19:41.301Z  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 6642 ms
2022-12-31T10:19:43.631Z  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-12-31T10:19:43.844Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
2022-12-31T10:19:43.906Z  INFO 1 --- [           main] c.e.s.SampleRestApiApplication           : Started SampleRestApiApplication in 11.273 seconds (process running for 13.171)

参考(公式)

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?