testcontainers / testcontainers/testcontainers-java

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

Abierto
#7,964 10 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

type/enhancement
Lenguaje dominante
Java
Estrellas
8.7k
Forks
1.9k
Merge medio
2 d 17 h
PR fusionados (30 d)
9

Descripción

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!

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Revisa org.testcontainers.utility.RyukContainer y RyukResourceReaper, junto con la documentación de configuración personalizada de Ryuk. Traza cómo se seleccionan el espacio de nombres del host del contenedor y la dirección de conexión, y determina después cómo una opción oficial podría admitir Docker userns-remap sin romper los entornos de Docker remoto. La implementación debe incluir pruebas que cubran la configuración admitida y el comportamiento de conexión.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
docker, java
Área
devops, testing
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.