How to read files and stdout from a running Docker container

前端 未结 5 784
南方客
南方客 2020-12-12 12:21

How would I go about starting an application in my host machine in order to read files and stdout from a running docker container?

Essentially I want to do this:

5条回答
  •  被撕碎了的回忆
    2020-12-12 12:58

    A bit late but this is what I'm doing with journald. It's pretty powerful.

    You need to be running your docker containers on an OS with systemd-journald.

    docker run -d --log-driver=journald myapp

    This pipes the whole lot into host's journald which takes care of stuff like log pruning, storage format etc and gives you some cool options for viewing them:

    journalctl CONTAINER_NAME=myapp -f

    which will feed it to your console as it is logged,

    journalctl CONTAINER_NAME=myapp > output.log

    which gives you the whole lot in a file to take away, or

    journalctl CONTAINER_NAME=myapp --since=17:45

    Plus you can still see the logs via docker logs .... if that's your preference.

    No more > my.log or -v "/apps/myapp/logs:/logs" etc

提交回复
热议问题