-
| I'd like to execute a command like this:  If I understand correctly, Testcontainers requires me to start the container first and then execute a command inside a running container. However, I don't want to start the container - I'd like to execute a command in the container synchronously and get a result. I suppose I have to "disable"  | 
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
| Hi @remal, Have a look at  | 
Beta Was this translation helpful? Give feedback.
-
| @remal Have you managed to run schemaSpy with Testcontainers? If so, can you share the setup, please? I'm also trying to do it but now I'm stuck. Here is something I came up with: private final GenericContainer<?> SCHEMA_SPY =
        new GenericContainer<>(DockerImageName.parse("schemaspy/schemaspy:6.1.0"))
            .withNetworkAliases("schemaspy")
            .withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint(""))
            .withCommand("sh", "-c", "sleep 50000 && echo \"hello\"", "HELLO_TESTCONTAINERS")
            .withNetwork(NETWORK)
            .withStartupCheckStrategy(
                new IndefiniteWaitOneShotStartupCheckStrategy()
            )
            .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("SchemaSpy")));
    @Test
    @SneakyThrows
    void test() {
        Startables.deepStart(SCHEMA_SPY);
        while (!SCHEMA_SPY.isRunning()) {
            Thread.yield();
        }
        SCHEMA_SPY.execInContainer(
            "java -jar schemaspy-6.1.0.jar -t pgsql11 -db %s -host postgres -u %s -p %s -debug && tail -f /dev/null"
                .formatted(POSTGRES.getDatabaseName(), POSTGRES.getUsername(), POSTGRES.getPassword())
        );
        SCHEMA_SPY.execInContainer("tar", "-czvf", "/output/output.tar.gz", "/output");
        SCHEMA_SPY.copyFileFromContainer(
            "/output/output.tar.gz",
            Path.of(getClass().getResource("/").getPath(), "output.tar.gz")
                .toAbsolutePath()
                .toString()
        );
        SCHEMA_SPY.stop();
    }Here is the idea: 
 But actually the  So, the  | 
Beta Was this translation helpful? Give feedback.
Hi @remal,
Have a look at
OneShotStartupCheckStrategy:https://www.testcontainers.org/features/startup_and_waits/#one-shot-startup-strategy-example