testcontainers / testcontainers-java

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.org
MIT License
8.02k stars 1.65k forks source link

DockerComposeContainer: random failures with SocatContainer or ContainerisedDockerCompose #768

Open DmPanov opened 6 years ago

DmPanov commented 6 years ago

Versions


Exception gets thrown either in `DockerComposeContainer#pullImages` or in `DockerComposeContainer#createServices`. Debugging showed me that after executing `CreateContainerCmd` compose container just doesn't get created sometimes, `docker container ps --all` shows nothing.
unit8knawara commented 6 years ago

Also affected by this issue

kiview commented 6 years ago

This is only happen for Docker-Compose? How do you create the container?

DmPanov commented 6 years ago

@kiview yes, only for Docker-Compose

class TeamCityInDocker(id: String) : DockerComposeContainer<TeamCityInDocker>(id, Paths.get(TeamCityInDocker::class.java.classLoader.getResource("docker-compose.yml").toURI()).toFile()) {
    init {
        val ambassadorContainer = DockerComposeContainer::class.java
                .declaredFields.first { it.type == SocatContainer::class.java }
                .apply { isAccessible = true }
                .get(this) as SocatContainer
        ambassadorContainer.withStartupTimeout(Duration.ofMinutes(5))
        withLocalCompose(true) // or false
    }
version: "3"
services:
  teamcity-server:
    image: teamcity-server:2018.1.1
    ports:
      - "8111:8111"
  teamcity-agent1:
    image: teamcity-agent:2018.1.1
  teamcity-agent2:
    image: teamcity-agent:2018.1.1
  # alpine:3.7 + git-daemon here
  git-server:
    build:
      context: git-daemon
      dockerfile: Dockerfile
    ports:
      - "9418:9418"
  # ubuntu:18.04 + popa3d here
  mail-server:
    build:
      context: mail-server
      dockerfile: Dockerfile
    ports:
      - "5025:25"
      - "5110:110"
kiview commented 6 years ago

You are not exposing services you want to use, I am unsure what the WaitStrategy will do in this case. Normally we would wait for the exposed ports of the services you would interact with through the SocatContainer.

Can you try exposing the services using withExposedService() on the DockerComposeContainer?

DmPanov commented 6 years ago

I forgot to include port mappings into example above, sorry. Edited