3

My Dockerfile is

FROM node:4

RUN npm install -g yarn

WORKDIR /app

I run docker run -d and mount my current working directory as a volume. All the deps are installed by yarn. I have a npm script to lint the files.

If I do docker exec -it [container] npm run lint it works as expected and I can see all the logs. But if I do docker exec -itd [container] npm run lint, it exits immediately which is expected. But I can't see the logs by running docker logs [container]. How do I reattach the exec or just see to the logs?

I tried docker attach [container] it goes to the repl of nodejs. Why is that?

stevemao
  • 1,423
  • 1
  • 16
  • 29

1 Answers1

5

As mentioned in "Docker look at the log of an exited container", you can use docker logs

docker logs -t <container>

That will show stdout/stderr (with timestamps because of the -t option).

For that last 50 lines of those logs:

docker logs -t <container id> | tail -n 50

Note: that would work only if npm run lint is run by your container (docker run <image> npm run lint)

If your docker exec exits immediately, then yes, there would be no logs produces by the container itself.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried the command but it doesn't seem to work. I'm running `docker run -d` and then `docker exec -itd [container]` so I doubt it's because it's running detach mode in detach mode. – stevemao Feb 03 '17 at 05:43
  • @stevemao Check first that your container did exit with docker ps. – VonC Feb 03 '17 at 05:44
  • @stevemao I have edited the answer: `docker logs` would display what the container does, not what `docker exec` does (since `docker exec` has stopped, it does not do anything anymore) – VonC Feb 03 '17 at 05:48
  • I'm surprised that there is no way to get the logs. Thanks for the answer :) – stevemao Feb 04 '17 at 00:21