0
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?

nablarch: nablarch-example-restをdockerコンテナにする方法

Last updated at Posted at 2024-05-06

はじめに:nablarch-example-restの課題

nablarch-example-restは、nablarchフレームワークのRESTアプリケーション実装例である。

ただし、nablarch-example-restはdocker用のexampleを提供していない。
かわりにwaitt(Web Application Integration Test Tool)ツールによるexampleが提供されているが、
waittは複数アプリの結合などを行うことが難しい上にメンテナンスされていないため、tomcatバージョンも変更困難である点が難点。

このページでは、より人気が高く機能も豊富であるdockerコンテナでnablarch-example-restを動かす方法を説明する。

前提条件

  • docker(インストール手順はこちらを参照)
  • jdk(8または17)
  • maven(ただし、maven wrapperがある場合は不要)

アクセス例

target\nablarch-example-rest-5u24.war は、手順に従って事前生成されている前提とする。
手順はhttps://github.com/nablarch/nablarch-example-restを参照。

compose.yml
services:
  backend:
      build: .
      tty: true
      ports:
        - 8080:8080
Dockerfile
# syntax=docker.io/docker/dockerfile:1
FROM tomcat:9.0-jre8-temurin

# ----------------ここから、tomcat managerを有効にする場合のみ使用。----------------
# tomcat managerのリソースを配置する(デフォルトでは、そもそもManagerページ自体が無い)。
# かわりに、mvコマンドを実行する手もある。
COPY --from=tomcat:9.0-jre8-temurin /usr/local/tomcat/webapps.dist/manager/ /usr/local/tomcat/webapps/manager/

# manager-guiロールを有効化する。
COPY tomcat-users.xml /usr/local/tomcat/conf/tomcat-users.xml
# ローカルホスト以外からアクセスできない制限を解除する。
COPY context.xml /usr/local/tomcat/webapps/manager/META-INF/context.xml
# ----------------ここまで、tomcat managerを有効にする場合のみ使用。----------------

# h2の仕様では、相対パスのみが使用される場合現在の作業ディレクトリが開始点として使用されます。
# tomcatコンテナイメージでは、デフォルトの作業ディレクトリは/usr/local/tomcatです。
# env.properties で nablarch.db.url=jdbc:h2:./h2/db/rest_example を設定する場合、/usr/local/tomcat/h2/db/が正しい配置場所です。
COPY ./h2/db/rest_example.mv.db /usr/local/tomcat/h2/db/
# /usr/local/tomcat/webapps/配下に、任意の名前でwarを配置する。この名前が後でアクセスする際のURLパスとなる。
# 例: http://localhost:8082/manager/html
COPY ./target/nablarch-example-rest-5u25.war /usr/local/tomcat/webapps/nablarch-example-rest.war

EXPOSE 8080

docker composeコマンドの実行

docker compose up -d

tomcatはどういう状態になっているのか

http://localhost:8080/manager/htmlにアクセスし、tomcat管理画面を表示して確認する。

/nablarch-example-restのコンテキストパスに、アプリが配置されている。
この時、APIのURLはhttp://localhost:8080/nablarch-example-rest/projectsとなる。

image.png

実際の画面表示

上手くいけば、http://localhost:8080/nablarch-example-rest/projectsへアクセスしたときに以下のように表示される。

image.png

オプション:tomcat管理画面を利用したい場合の詳細

このDockerfileの場合、tomcat管理画面が利用できない。
tomcat管理画面を利用したい場合は別記事を用意しているので、そちらを参照。

0
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
0
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?