Search code examples
testcontainerscockroachdb

Testcontainers execInContainer not working with CockroachDB


I'm using Testcontainers to start a CockroachDB instance with docker. I need to enable support for temporary tables by setting the property sql.defaults.experimental_temporary_tables.enabled to true.

When the machine is running, I can do it with:

docker exec -it CockroachDBHibernate ./cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';"

But when I try to run the same command with Testcontainers:

container.execInContainer(
                    "./cockroach sql --insecure -e \"SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';\"" );

I have the following error:

OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "./cockroach sql --insecure -e \"SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';\"": stat ./cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';": no such file or directory: unknown

Note that the error is visible via Container.ExecResult#getStdout(). Exit code is 126

I'm using Testcontainers 1.15.2 and CockroachDB v20.2.5

Thanks


Solution

  •  container.execInContainer( "sh", "-c", "./cockroach sql --insecure -e \"SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';\"" );