0

I am using the following:

  • m2 Mac (OS X Ventura 13.3)
  • Spring Boot v3.1.2
  • Test Containers v1.19.1
  • Docker Desktop v4.24.2

When I run my integration tests individually they pass but when running them with the following command:

mvn -f pom.xml clean package 

I get the following error

Could not find a valid Docker environment. Please check configuration

I have tried everything in this post but nothing seems to be working.

Has anybody else managed to get it to work on an m2 Mac ?

Here is a sample of the integration test configuration

@Testcontainers @AutoConfigureWebTestClient(timeout = "36000") @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class MyServiceIntegrationTests { @Container static PostgreSQLContainer<?> postgresqlContainer = new PostgreSQLContainer<>("postgres:15.1-alpine"); @BeforeAll static void beforeAll() { postgresqlContainer.start(); } @AfterAll static void afterAll() { postgresqlContainer.stop(); } @DynamicPropertySource static void setProperties(DynamicPropertyRegistry registry) { registry.add("spring.datasource.url", postgresqlContainer::getJdbcUrl); registry.add("spring.datasource.username", postgresqlContainer::getUsername); registry.add("spring.datasource.password", postgresqlContainer::getPassword); } 

This is my docker file

FROM maven:3.8.5-openjdk-18-slim AS build RUN mkdir -p workspace WORKDIR workspace COPY pom.xml /workspace COPY src /workspace/src RUN mvn -f pom.xml clean package FROM openjdk:18-alpine COPY --from=build /workspace/target/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","app.jar"] 

It is being run using docker-compose and fails on this command

RUN mvn -f pom.xml clean package

However, it works if I dont run the tests using docker-compose

10
  • This answer with 107 upvotes may be helpful: stackoverflow.com/a/75782220/14072498 Commented Oct 15, 2023 at 14:24
  • Is docker working properly ? For example, what's the output of docker ps ? Commented Oct 15, 2023 at 14:36
  • docker is running properly. The tests work when i run them individually in intellij but when i run them with mvn clean package they dont. @RoarS. I have tried the solution in that thread and it still doesnt work Commented Oct 15, 2023 at 14:46
  • This is a similar case, without any accepted answer: stackoverflow.com/questions/68061837/… Commented Oct 15, 2023 at 15:10
  • 1
    That works, it must be an issue when running through docker-compose Commented Oct 15, 2023 at 15:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.