Testcontainers はユニットテストの起動と終了と共にdockerコンテナも起動と終了してくれるライブラリ。windowsというかWSL2で動かすには若干の追加設定が必要だった。
環境
手順
まず、Docker Desktopを使わずにWSL2でVSCode Remote Containerを使う - Qiitaにあるようにtcpをlistenする。
{ "debug": false, "tls": false, "hosts": ["tcp://127.0.0.1:2375", "unix:///var/run/docker.sock"] }
次に、https://www.testcontainers.org/features/configuration/ にあるようにdocker.host
を修正する。C:/Users/myuser/.testcontainers.properties
を以下のように修正する。
docker.host=tcp://localhost:2375
マニュアルによるとdocker.host
は以下三種類の指定方法があるとのことだが、自分の環境では3.のクラスパスは上手くいかなかった。なので2.のユーザホームに.testcontainers.properties
(先頭に"."が必要なので注意)を置く方法にした。
1. Environment variables 2. .testcontainers.properties in user's home folder. Example locations: Linux: /home/myuser/.testcontainers.properties Windows: C:/Users/myuser/.testcontainers.properties macOS: /Users/myuser/.testcontainers.properties 3. testcontainers.properties on the classpath.