Testcontainer inside Openshift - Docker Non-root #11355
-
|
Hello everyone, I am facing a problem that is bothering me quite a bit, and I am not keen on the alternative of using an external database. Does anyone have any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
I've dealt with this exact issue running TestContainers in OpenShift CI pipelines. The core problem is that OpenShift runs containers as non-root with a random UID, which conflicts with how Docker/Podman expects to operate. Solutions (pick one)Option 1: Use Podman as the container runtime (Recommended for OpenShift)TestContainers 2.x supports Podman natively. In your OpenShift pipeline: # testcontainers.properties or environment variables
docker.host=unix:///run/podman/podman.sock
testcontainers.ryuk.disabled=true
ryuk.container.privileged=falseAnd in your GitLab CI config, use a Podman-enabled image: image: quay.io/podman/stable
script:
- podman system service -t 0 unix:///run/podman/podman.sock &
- ./gradlew testOption 2: Docker-in-Docker (DinD) with privileged SCCIf you must use Docker, you need the Docker socket or a DinD sidecar: # OpenShift - grant the anyuid SCC to the service account
oc adm policy add-scc-to-user anyuid -z gitlab-runner -n your-namespaceThen mount the Docker socket or run DinD as a sidecar. Option 3: Disable Ryuk + use pre-started containersRyuk (the cleanup container) often fails in restricted environments: TESTCONTAINERS_RYUK_DISABLED=true
DOCKER_HOST=tcp://docker-in-docker-service:2375Option 4: Skip TestContainers in CI, use real servicesIn OpenShift, you often already have PostgreSQL/Redis/Kafka as services. Use a test profile that connects to those instead: # application-ci.properties
quarkus.datasource.jdbc.url=jdbc:postgresql://postgresql:5432/testdbWhat I'd recommendFor OpenShift specifically, Option 1 (Podman) is the cleanest. Podman is rootless by design and is the default container runtime in OpenShift 4.x anyway. TestContainers 2.x has much better Podman support than 1.x. |
Beta Was this translation helpful? Give feedback.
I've dealt with this exact issue running TestContainers in OpenShift CI pipelines. The core problem is that OpenShift runs containers as non-root with a random UID, which conflicts with how Docker/Podman expects to operate.
Solutions (pick one)
Option 1: Use Podman as the container runtime (Recommended for OpenShift)
TestContainers 2.x supports Podman natively. In your OpenShift pipeline:
And in your GitLab CI config, use a Podman-enabled image: