WildFly Docker イメージに war ファイルをデプロイして新たなイメージを作る
WildFly という JVM サーバがあります.
WildFly はもともと JBoss Application Server という名称でした.
JBossは現在、コミュニティ版 WildFly とエンタープライズ版 JBoss Enterprise Application Platform で構成されています.
今回はこの WildFly に war ファイルをデプロイして新たなイメージを作成したいと思います.
Dockerfile
まずは Dockerfile です.
FROM jboss/wildfly
ADD target/demoapi-0.0.1-SNAPSHOT.war /opt/jboss/wildfly/standalone/deployments/
/opt/jboss/wildfly/standalone/deployments/ 内に war ファイルを置くことで WildFly 起動時にアプリも同時に起動させることができます.
ファイル階層は以下のような感じです.
$ ls
Dockerfile checkstyle.xml mvnw pom.xml target
README.md lib mvnw.cmd src
これでビルドの準備ができました.
docker build
WildFly をベースイメージとして war がデプロイ済みの新たなイメージを作成します.
$ docker build --tag=wildfly-prototype .
Sending build context to Docker daemon 132.6MB
Step 1/2 : FROM jboss/wildfly
---> 2602b4852593
Step 2/2 : ADD target/demoAPI-0.0.1-SNAPSHOT.war /opt/jboss/wildfly/standalone/deployments/
---> 464e57ff86e8
Successfully built 464e57ff86e8
Successfully tagged wildfly-prototype:latest
作成したイメージが確認できます.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wildfly-prototype latest 464e57ff86e8 29 seconds ago 724MB
jboss/wildfly latest 2602b4852593 4 weeks ago 675MB
作成したイメージを起動します.
docker run -it wildfly-prototype
prototype | 08:08:14,212 INFO [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] (ServerService Thread Pool -- 75) Initializing ExecutorService 'applicationTaskExecutor'
prototype | 08:08:15,578 INFO [springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper] (ServerService Thread Pool -- 75) Context refreshed
prototype | 08:08:15,807 INFO [springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper] (ServerService Thread Pool -- 75) Found 1 custom documentation plugin(s)
prototype | 08:08:15,979 INFO [springfox.documentation.spring.web.scanners.ApiListingReferenceScanner] (ServerService Thread Pool -- 75) Scanning for api listing references
prototype | 08:08:16,421 INFO [springfox.documentation.spring.web.readers.operation.CachingOperationNameGenerator] (ServerService Thread Pool -- 75) Generating unique operation named: helloUsingGET_1
prototype | 08:08:16,477 INFO [com.example.demoapi.DemoApiApplication] (ServerService Thread Pool -- 75) Started DemoApiApplication in 15.537 seconds (JVM running for 48.519)
.war としてデプロイした Spring のアプリが起動していることが確認できます.
以上です.