I'm trying to start a jar file inside a running container.
In order to do this I use this command docker exec -t -d [containerID] java -jar jarname.jar
.
The command is successfully executed but I am unable to see its output.
Docker allocates a new tty in the host but how can I see its output?
What am I doing wrong?
Asked
Active
Viewed 4,210 times
3

user2419952
- 31
- 1
- 4
1 Answers
2
How about removing the -d
flag, then you will get the output on stdout.
Can use shell redirection and backgrounding on the docker command if needed.
I would also remove the '-t' flag unless your Java program specifically needs a tty.

Bryan
- 11,398
- 3
- 53
- 78
-
Sorry, my bad, was thinking of 'docker run'; have removed old answer and tried again. – Bryan Nov 13 '14 at 10:22
-
I do not understand why with -d flag I can't see its output. I will try to explain better what I want to do. I'm using docker-py API to run this command inside a running container using openstack and novadocker driver, I call the execute method (in docker-py) but if I set detach to False I will get a timeout error because POST request never return contrary to docker API documentation [link](https://docs.docker.com/reference/api/docker_remote_api_v1.15/#exec-start). I do not know if it is a bug or if I'm doing something wrong. – user2419952 Nov 13 '14 at 10:49
-
The docker command-line communicates with the docker daemon over a socket; the daemon starts the new child process. The cli needs to arrange to fetch output from the new process over that socket. I just checked the Docker source code, and '-d' turns off that log-file fetching. – Bryan Nov 13 '14 at 11:40
-
You might find looking at the docker daemon log helpful, and maybe turning on its debug mode. – Bryan Nov 13 '14 at 11:41
-
Re 'POST never returns' - see [docs for attach](https://docs.docker.com/reference/api/docker_remote_api_v1.15/#attach-to-a-container) - this is how the process' output is returned to you if you use the API. – Bryan Nov 13 '14 at 11:47
-
Ok you are absolutely right but my problem is that the jar never returns so also the POST request never returns. I want to start the command inside the container and after obtain its output with logs API. – user2419952 Nov 13 '14 at 15:32
-
Does it work if you exec something like 'ps' instead of the jar? – Bryan Nov 13 '14 at 16:44
-
Yes it works also if I exec a jar that finishes at a certain point and the POST request returns its output as for attach stream. But I want to execute a jar that never finishes, detach from it and retrieve its output only when I want. – user2419952 Nov 13 '14 at 17:21
-
Exec'd processes are very like containers - I suspect you can run it in detatched mode and [fetch the logs](https://docs.docker.com/reference/api/docker_remote_api_v1.15/#get-container-logs) when you want using the 'exec id' you used to start it. – Bryan Nov 13 '14 at 17:33
-
Unfortunately it does not work. I hoped that this was the solution but it is not. In [this image](http://imgur.com/xwJNvU8) you can see that after call exec docker tries to attach stdout but since the program never ends the exec call will never return. – user2419952 Nov 13 '14 at 19:10
-
You need to set detached:true – Bryan Nov 13 '14 at 19:31
-
This happens also with detach=True, for this reason I do not know if it is a bug or if I'm doing something wrong. – user2419952 Nov 13 '14 at 19:43