testcontainers / testcontainers/testcontainers-java

Starting docker-compose test containers as non-root user

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

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

area/docker-compose resolution/waiting-for-info type/question
主要言語
Java
スター
8.7k
フォーク
1.9k
平均マージ
2日 17時間
マージ済み PR(30日)
9

説明

Similar to: https://github.com/testcontainers/testcontainers-java/issues/2590

I'm trying to start our docker-compose based testcontainers tests, and pass in the local username from the running system, in order that the container can write files to mounted volumes with the correct permissions.

I tried a compose with:

version: "3.7"
services:
  myservice:
    image: xxx
    user: ${CURRENT_USER}
    ...
    volumes:
      ./target/:/target

And passed in CURRENT_USER environment variable to testcontainers using:

  env = new DockerComposeContainer(new File("src/main/docker/docker-compose.yml"));
  env.withLocalCompose(true);
  env.withEnv("CURRENT_USER", System.getProperty("user.name"));

However, this fails with:

Cannot start service my server: unable to find user bmiddleton: no matching entries in passwd file

I presume it's looking for that user in the ryuk container, and not the OS - where the user does exist.

How can I get a testcontainers test running from a docker compose file to write its files using the current user of the operating system?

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

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

はじめの一歩

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

調査の方向性

src/main/docker/docker-compose.yml を使用した DockerComposeContainer のセットアップから始め、withLocalCompose(true) と withEnv("CURRENT_USER", System.getProperty("user.name")) を含めます。Compose ベースのテスト失敗を再現し、Compose サービスのユーザーとマウントされた ./target/ ボリュームがどのように扱われているかを調査します。サービスが passwd lookup error なしで、現在の OS ユーザーの権限を使ってマウントされたファイルに書き込めるようになれば完了です。

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

評価

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

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

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