Facing "error while creating mount source path " issue while executing test case from my service. Seems to me this issue only face in when I use of DockerComposeContainer. Without DockerComposeContainer I can able to execute my test case properly. I am using windows OS.

Here is the exception detail:

Creating network "ocfqeycqlhgm_default" with the default driver
Creating ocfqeycqlhgm_job-mock_1 ...
Creating ocfqeycqlhgm_mongo_1    ...
Creating ocfqeycqlhgm_job-mock_1 ... error
ERROR: for ocfqeycqlhgm_job-mock_1  Cannot start service job-mock: error while creating mount source path '/d/ProjectsAndWorkspace/docker_playground/docker-spring-webflux-master/application/candidate-service/src/test/resources/data/job-init.json': mkdir /d: file exists
Creating ocfqeycqlhgm_mongo_1    ... error
ERROR: for ocfqeycqlhgm_mongo_1  Cannot start service mongo: error while creating mount source path '/d/ProjectsAndWorkspace/docker_playground/docker-spring-webflux-master/application/candidate-service/src/test/resources/data': mkdir /d: file exists
ERROR: for job-mock  Cannot start service job-mock: error while creating mount source path '/d/ProjectsAndWorkspace/docker_playground/docker-spring-webflux-master/application/candidate-service/src/test/resources/data/job-init.json': mkdir /d: file exists
ERROR: for mongo  Cannot start service mongo: error while creating mount source path '/d/ProjectsAndWorkspace/docker_playground/docker-spring-webflux-master/application/candidate-service/src/test/resources/data': mkdir /d: file exists

Code:

@Testcontainers
public abstract class BaseTest {

    private static final Service MONGO = Service.create(
         "mongo", 27017, "0", "mongodb://candidate_user:candidate_password@%s:%s/candidate", "HOST_PORT1"
    );

    private static final Service JOB = Service.create(
            "job-mock", 1080, "0", "http://%s:%s/job/", "HOST_PORT2"
    );

    @ClassRule
    private static final DockerComposeContainer<?> compose = new DockerComposeContainer<>(new File("docker-compose.yaml"));

    @DynamicPropertySource
    static void mongoProperties(DynamicPropertyRegistry registry){
        compose
                .withEnv(MONGO.getHostPortEnvVariable(), MONGO.getHostPort())
                .withEnv(JOB.getHostPortEnvVariable(), JOB.getHostPort())
                .withExposedService(MONGO.getName(), MONGO.getPort(), Wait.forListeningPort())
                .withExposedService(JOB.getName(), JOB.getPort(), Wait.forHttp("/health").forStatusCode(200))
                .start();
        var mongoHost = compose.getServiceHost(MONGO.getName(), MONGO.getPort());
        var mongoPort = compose.getServicePort(MONGO.getName(), MONGO.getPort());
        var jobHost = compose.getServiceHost(JOB.getName(), JOB.getPort());
        var jobPort = compose.getServicePort(JOB.getName(), JOB.getPort());
        registry.add("spring.data.mongodb.uri", () -> String.format(MONGO.getUri(), mongoHost, mongoPort));
        registry.add("job.service.url", () -> String.format(JOB.getUri(), jobHost, jobPort));
    }

}
@SpringBootTest
@AutoConfigureWebTestClient
class CandidateServiceIT extends BaseTest {

    @Autowired
    private WebTestClient client;

    @Test
    void allCandidatesTest() {
        this.client.get()
                .uri("/candidate/all")
                .exchange()
                .expectStatus().is2xxSuccessful()
                .expectBody()
                .jsonPath("$").isNotEmpty();
    }
}

Docker-compose.yaml:

version: "3.0"
services:
  mongo:
    image: mongo
    ports:
      - "${HOST_PORT1:-27017}:27017"
    volumes:
      - ./src/test/resources/data:/docker-entrypoint-initdb.d

  job-mock:
    image: mockserver/mockserver
    ports:
      - "${HOST_PORT2:-1080}:1080"
    environment:
      MOCKSERVER_INITIALIZATION_JSON_PATH: /config/init.json
    volumes:
      - ./src/test/resources/data/job-init.json:/config/init.json     
  candidate-service:
    build: .
    image: candidate-service
    depends_on:
      - mongo
    ports:
      - "8080:8080"
    profiles:
      - app
    environment:
      spring.data.mongodb.uri: "mongodb://candidate_user:candidate_password@mongo:27017/candidate"

I did change and provide absolute path in docker-compose file like below then after facing "ERROR: for gztdztlcog8h_job-mock_1 Cannot create container for service job-mock: invalid mode: /config/init.json"

volumes:
      #- "./src/test/resources/data:/docker-entrypoint-initdb.d"
      - "/d:/ProjectsAndWorkspace/docker_playground/docker-java-playground/candidate-service/src/test/resources/data:/docker-entrypoint-initdb.d"

To resolve "ERROR: for gztdztlcog8h_job-mock_1 Cannot create container for service job-mock: invalid mode: /config/init.json" I did change volumes by appending :ro or :rw and try to run the Test case now facing

2023-12-12T09:47:59.172+05:30 ERROR 11756 --- [           main] tc.docker/compose:1.29.2                 : Log output from the failed container:
Volume /d:/ProjectsAndWorkspace/docker_playground/docker-java-playground/candidate-service/src/test/resources/data:/docker-entrypoint-initdb.d:rw has incorrect format, should be external:internal[:mode]

NOTE: restarting docker service not help

0

There are 0 best solutions below