About the withCmd command of docker-java

241 Views Asked by At

I want to ask how I use the withCmd method as follows:

commands = new String[]{"echo","test:111 | chpasswd"};
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd("b6b571d5469a")
       .withCmd(commands).withAttachStdout(true).withAttachStderr(true).exec();

I am changing the user password! But it actually becomes the output string Just like when I execute echo "test:111 | chpasswd" under linux How can I make it execute the commandecho test:111 | chpasswd

1

There are 1 best solutions below

0
On

Why don't you try with a shell command

.withCmd("sh", "-c", "echo 'test:111' | chpasswd")