How to pipe commands in testcontainers execInContainer metod

Viewed 433

I would like to run piped commands on docker through testcontainer execInContainer method. I'm able to run a single command (e.g. execInContainer("redis-cli", "keys", "*"), but when providing a pipe (e.g. execInContainer("redis-cli", "keys", "*", "|", "grep", "-v", "test")) it reads it as it belongs to the previous command (ERR wrong number of arguments for 'keys' command). What I want to achieve is to remove all keys from redis, beside one. The full script is as follow redis-cli keys * | grep -v test | xargs redis-cli DEL. Any idea how could I do this?

1 Answers

I raised this issue with the testcontainers team.

It looks like you can do:

execInContainer("sh", "-c", "foo | bar")

Can you please try this? It should work.

Related