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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With