Run a command in a running container, get log and wait for completion

384 views
Skip to first unread message

Luciano Molinari

unread,
Dec 4, 2015, 7:02:33 AM12/4/15
to docker-java-dev
Hi all,

I have a running container and I want to run a bash script in it. I've been able to run the command, but, as it takes a few seconds to complete, I'd like to make the caller Thread to wait until the command is completed and, if possible, to get the output of it.

I've gone through the examples here (https://github.com/docker-java/docker-java/blob/master/src/test/java/com/github/dockerjava/core/command/ExecStartCmdImplTest.java), but couldn't find a way to achieve what I want.

Any ideas?

Thanks in advance.

Kind regards,
Luciano

zhao peng

unread,
Jan 18, 2016, 2:16:25 AM1/18/16
to docker-java-dev
hi. do u resolve this problem?

marcuslinke

unread,
Jan 18, 2016, 2:52:14 AM1/18/16
to docker-java-dev
This should be solvable through docker exec functionality (see https://docs.docker.com/engine/reference/api/docker_remote_api_v1.21/#exec-create and https://docs.docker.com/engine/reference/api/docker_remote_api_v1.21/#exec-start). There are equivalent APIs in docker-java. Meanwhile (in the latest 3.0.0-SNAPSHOT) there is experimental support for passing local STDIN to the container also (see https://github.com/docker-java/docker-java/blob/master/src/test/java/com/github/dockerjava/netty/exec/ExecStartCmdExecTest.java) for examples.

Hope this helps

Marcus

shengb...@gmail.com

unread,
Mar 8, 2017, 3:10:43 AM3/8/17
to docker-java-dev
Hi,I want to ask you a question.You said you have been able to run the command in a running container.How do you finish.Did you follow the example here (https://github.com/docker-java/docker-java/blob/master/src/test/java/com/github/dockerjava/core/command/ExecStartCmdImplTest.java).I use this example and want to send stdin data to a running container.When I send "ls" command to a running container.and want to see the output.But to my surprise,it didn't get anything.Could you tell me why?Thanks a lot.
Reply all
Reply to author
Forward
0 new messages