야미의 개발

Testcontainers Could not find a valid Docker environment (Status 400) 해결 방법 본문

카테고리 없음

Testcontainers Could not find a valid Docker environment (Status 400) 해결 방법

채야미 2026. 1. 18. 23:20

 

갑자기 테스트가 깨져서 로컬에서 테스트를 돌렷는데 테스트컨테이너에 연결 못하는 상황발생...

 

Docker Desktop을 최신 버전(4.56.0 / Engine 29.1.3)으로 업데이트한 이후, Testcontainers 실행 시 아래 오류가 발생했다.

  • BadRequestException (Status 400)
  • Could not find a valid Docker environment

Docker 자체(docker info, docker version)는 정상 동작했지만, Testcontainers가 Docker 환경을 찾지 못하고 실패했다.

 

 

it":{"ID":""},"SecurityOptions":null,"CDISpecDirs":null,"Warnings":null})As no valid configuration was found, execution cannot continue.
    See https://java.testcontainers.org/on_failure.html for more details.

UserServiceTest > initializationError FAILED
    java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
        at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$7(DockerClientProviderStrategy.java:274)
        at java.base/java.util.Optional.orElseThrow(Optional.java:403)
        at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:265)
        at org.testcontainers.DockerClientFactory.getOrInitializeStrategy(DockerClientFactory.java:154)
        at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:196)
        at org.testcontainers.DockerClientFactory$1.getDockerClient(DockerClientFactory.java:108)
        at com.github.dockerjava.api.DockerClientDelegate.authConfig(DockerClientDelegate.java:109)
        at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:316)
        at com.chapssals.kohee.config.MySQLContainerExtension.getOrStart(MySQLContainerExtension.kt:97)
        at com.chapssals.kohee.config.MySQLContainerExtension.beforeAll(MySQLContainerExtension.kt:20)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

ReportControllerTest STANDARD_OUT
    21:00:57.519 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.chapssals.kohee.api.v1.report.ReportControllerTest]: ReportControllerTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    21:00:57.548 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.chapssals.kohee.KoheeApplication for test class com.chapssals.kohee.api.v1.report.ReportControllerTest
    21:00:57.549 [Test worker] INFO org.testcontainers.DockerClientFactory -- Testcontainers version: 2.0.1

ReportControllerTest > initializationError FAILED
    java.lang.IllegalStateException: Previous attempts to find a Docker environment failed. Will not retry. Please see logs and check configuration
        at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:229)
        at org.testcontainers.DockerClientFactory.getOrInitializeStrategy(DockerClientFactory.java:154)
        at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:196)
        at org.testcontainers.DockerClientFactory$1.getDockerClient(DockerClientFactory.java:108)
        at com.github.dockerjava.api.DockerClientDelegate.authConfig(DockerClientDelegate.java:109)
        at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:316)
        at com.chapssals.kohee.config.MySQLContainerExtension.getOrStart(MySQLContainerExtension.kt:97)
        at com.chapssals.kohee.config.MySQLContainerExtension.beforeAll(MySQLContainerExtension.kt:20)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

ChangePasswordControllerTest STANDARD_OUT
    21:00:57.553 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.chapssals.kohee.api.v1.user.ChangePasswordControllerTest]: ChangePasswordControllerTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    21:00:57.569 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.chapssals.kohee.KoheeApplication for test class com.chapssals.kohee.api.v1.user.ChangePasswordControllerTest
    21:00:57.570 [Test worker] INFO org.testcontainers.DockerClientFactory -- Testcontainers version: 2.0.1

ChangePasswordControllerTest > initializationError FAILED
    java.lang.IllegalStateException: Previous attempts to find a Docker environment failed. Will not retry. Please see logs and check configuration
        at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:229)
        at org.testcontainers.DockerClientFactory.getOrInitializeStrategy(DockerClientFactory.java:154)
        at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:196)
        at org.testcontainers.DockerClientFactory$1.getDockerClient(DockerClientFactory.java:108)
        at com.github.dockerjava.api.DockerClientDelegate.authConfig(DockerClientDelegate.java:109)
        at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:316)
        at com.chapssals.kohee.config.MySQLContainerExtension.getOrStart(MySQLContainerExtension.kt:97)
        at com.chapssals.kohee.config.MySQLContainerExtension.beforeAll(MySQLContainerExtension.kt:20)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

UserConfigControllerTest STANDARD_OUT
    21:00:57.574 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.chapssals.kohee.api.v1.user.UserConfigControllerTest]: UserConfigControllerTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    21:00:57.579 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.chapssals.kohee.KoheeApplication for test class com.chapssals.kohee.api.v1.user.UserConfigControllerTest
    21:00:57.579 [Test worker] INFO org.testcontainers.DockerClientFactory -- Testcontainers version: 2.0.1

https://forums.docker.com/t/testcontainer-stopped-working-after-updating-docker-desktop-to-v4-56-0/150823

 

TestContainer stopped working after updating Docker Desktop to v4.56.0

Currently I’m using org.testcontainers:testcontainers:1.20.6 and after updating Docker Desktop to v4.56.0, now my tests stopped working. [Test worker] INFO o.testcontainers.images.PullPolicy - Image pull policy will be performed by: DefaultPullPolicy() [

forums.docker.com

 

다음 이슈에 해결 방안이 찾으니까 나옴

 

Docker Engine v29부터 Docker API 최소 버전 관련 변경이 있었고,
Testcontainers 내부에서 사용하는 docker-java 클라이언트의 API 버전 문제로 인해 /info 호출이 400으로 실패하는 케이스가 있다.


해결 방법

테스트 리소스 경로에 docker-java.properties 파일을 추가하고 API 버전을 명시했다.

파일 생성:
src/test/resources/docker-java.properties

 

내용:

api.version=1.44

 

로컬에만 적용 했엇는데 배포 파이프라인에서도 도커 버전이 올라가서, 똑같은 문제가 발생했었다.

 

로컬 말고 배포 서버에도 다음 설정을 해서 지금은 임시 조치를 해두었다.

내부 테스트 컨테이너 버전을 올리던지 해서 제대로 해결해야 할듯..!

Comments