testcontainers / testcontainers/testcontainers-java

[Enhancement]: Being able to use Ryuk in (CI) environment where Docker "userns-remap" mode is active

オープン
#7,964 コメント 10 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

type/enhancement
主要言語
Java
スター
8.7k
フォーク
1.9k
平均マージ
2日 17時間
マージ済み PR(30日)
9

説明

Module

Core

Proposal

Hello,

I'm using Testcontainers in an on-prem GitLab CI environment, where the GitLab runner hosts have their Docker server with userns-remap turned on.
I ran into a couple of issues related to Ryuk in this case.
First, from what I read on https://java.testcontainers.org/features/configuration/#customizing-ryuk-resource-reaper, the Ryuk container must be started as a privileged container.
That's the reason why I get the following error when Testcontainers tried launching the Ryuk container:

...
com.github.dockerjava.api.exception.BadRequestException: Status 400: {"message":"privileged mode is incompatible with user namespaces.  You must run the container in the host namespace when running privileged mode"}
...

As a quick hack, I worked around this issue by "monkeypatching" org.testcontainers.utility.RyukContainer and adding:

    cmd
        .getHostConfig()
        ...
        .withUsernsMode("host")  /// <= added

The Ruyk container could then start fine.

But due to the fact the GitLab runner container conforms to this userns-remap mode (and thus not Ruyk as per the above), Testcontainers was not able to connect to Ryuk:

...
WARN --- [containers-ryuk] o.t.utility.RyukResourceReaper : Can not connect to Ryuk at 172.17.0.1:35592

Again, I had to resort to monkeypatching org.testcontainers.utility.RuykResourceReaper to have:

...
// String host = ryukContainer.getHost();
String host = ryukContainer.getCurrentContainerInfo().getNetworkSettings().getIpAddress();
// Integer ryukPort = ryukContainer.getFirstMappedPort();
Integer ryukPort = ryukContainer.getExposedPorts().get(0);
...

My understanding is that this fix is obviously not portable in environments where the Docker host is not local to where Testcontainers is running.
But bar changing my CI environment setup to drop the userns-remap mode, I don't see any other solution to my issue.

What do you think of having "official support" for such a workaround in Testcontainers, so I don't have to monkeypatch Java classes... 🤓
If not via a setting (e.g. ryuk.container.userns_mode=host or something related), maybe via a way to customize the behavior of Testcontainers dynamically?

Thanks!

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

org.testcontainers.utility.RyukContainer と RyukResourceReaper、およびカスタム Ryuk 設定のドキュメントを確認します。コンテナのホスト名前空間と接続アドレスがどのように選択されるかを追跡し、リモート Docker 環境を壊すことなく Docker userns-remap をサポートできる公式オプションの方法を判断します。完了時には、サポートされる設定と接続動作を対象とするテストを含める必要があります。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
docker, java
領域
devops, testing
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。