Why Testcontainers withEnv Does Not Proxy Image Pulls
Configure the Docker daemon for a failed pull; container proxy variables only reach programs after the container is created.
If Testcontainers fails while pulling an image, the future container's withEnv settings cannot help. The Docker daemon performs that registry download before the container exists.
| Failed operation | Proxy configuration to inspect |
|---|---|
| Image pull | The Docker daemon used by the test and its registry route |
| Download inside the running container | The application's supported inputs in that container |
| Java test connects to Docker or the app | The Java-side client making that connection |
For the second case, add environment variables to the existing GenericContainer definition:
container
.withEnv("http_proxy", "http://proxy.example:8080")
.withEnv("https_proxy", "http://proxy.example:8080");For an in-container download allowed to use a public HTTP endpoint, fill those values from the HTTP proxy list. The program in the image must read those variables. They do not turn an arbitrary database socket into HTTP proxy traffic. The endpoint must also be reachable from the container: its 127.0.0.1 refers to itself.
For the first case, find the Docker environment Testcontainers actually uses. A remote daemon or Docker Desktop may take configuration from a different source than native local dockerd. Keep local test services and the Docker API on their intended routes when adding a broad proxy default.