12

If I run a command using docker's exec command, like so:

docker exec container gulp

It simply runs the command, but nothing is outputted to my terminal window.

However, if I actually go into the container and run the command manually:

docker exec -ti container bash
gulp

I see gulp's output:

[13:49:57] Using gulpfile ~/code/services/app/gulpfile.js
[13:49:57] Starting 'scripts'...
[13:49:57] Starting 'styles'...
[13:49:58] Starting 'emailStyles'...
...

How can I run my first command and still have the output sent to my terminal window?

Side note: I see the same behavior with npm installs, forever restarts, etc. So, it is not just a gulp issue, but likely something with how docker is mapping the stdout.

Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131

1 Answers1

9

How can I run my first command and still have the output sent to my terminal window?

You need to make sure docker run is launched with the -t option in order to allocate a pseudo tty.
Then a docker exec without -t would still work.

I discuss docker exec -it here, which references "Fixing the Docker TERM variable issue ")

docker@machine:/c/Users/vonc/prog$ d run --name test -dit busybox
2b06a0ebb573e936c9fa2be7e79f1a7729baee6bfffb4b2cbf36e818b1da7349
docker@machine:/c/Users/vonc/prog$ d exec test echo ok
ok
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • How can the `-t` be used in the Dockerfile's RUN directive? – Michael Irigoyen Mar 09 '16 at 15:30
  • 1
    @MichaelIrigoyen it is not: `-t` is a `docker run` *runtime* option, not a static `docker build` directive. – VonC Mar 09 '16 at 15:33
  • Our actual problem comes from the Dockerfile's RUN directive. The example given was just how we were able to repro it easiest. – Michael Irigoyen Mar 09 '16 at 15:35
  • @MichaelIrigoyen The example given has nothing to do with Dockerfile and docker build. The example given needs a running container, not a building image. – VonC Mar 09 '16 at 15:36
  • But it does, our RUN command runs a bash script that includes npm installs, gulp, and forever starts. The log it produces during runtime provides none of the verbose information we need. Running that same bash script manually produces the same issue, not enough logging. Running that script with `-t` shows the extra stuff we need. As I said, the example above is the easiest way to repro the issue. Any ideas? – Michael Irigoyen Mar 09 '16 at 15:39
  • 1
    @MichaelIrigoyen I get it now: RUN is indeed executed in an intermediate container. The real question is: can I set `-t` when docker runs an intermediate container during `docker build`? I'll look into that. – VonC Mar 09 '16 at 15:40
  • @MichaelIrigoyen last October, it was not working: http://stackoverflow.com/q/33137483/6309 – VonC Mar 09 '16 at 15:43