I want to run tail -f /var/log/xxx.log file from existing container, where /var/log/xxx.log is a log file inside host.

From docs and with google search, I have found that this is possible with bind mount.

But I couldn't run tail -f /var/log/xxx.log . Any advice or proper document about bind mount would be appreciated.

Thanks in advance


You can import the log directory as a volume when you run your Docker image, and run your command through Docker that way. An example could be running:
$ docker run -v /path/to/log:/working your_image tail -f /working/xxx.log
, where you have to replace /path/to/log with /var/log, and your_image with the name of your image.

The -v command requires the path to your folder (within the Host machine) and the location where the path should be mounted to (withing the container). The two locations are place before and after a colon.

In the case above, the path /path/to/log is the path to your log folder on your machine, and that location it is mounted to /working within the container. Finally, when running the tail command, you access your log file through the /working directory, which is within the container.

More information about all this can be found here!

  • 1
    Thank you for your response @Ali Nobari, .but I want to do this with a running docker. How can I do this? – Jasmine Apr 25 '18 at 19:11
  • 1
    You're welcome @Jasime. For running within a running container, you would use exec. As long as you have attached the file as a volume as mentioned above, you will be able to access your file through that command. If this is the answer to your question, let me know so I can attach it to my original answer! – Ali Nobari Apr 25 '18 at 20:17
  • Could I mount bind in this situation? – Jasmine Apr 26 '18 at 14:10
  • 1
    @Jasmine, yes you can. If you look at the link I attached at the end of my answer, it will explain the difference between using a volume and a bind mount. You can use whichever one, as you see fit. – Ali Nobari Apr 26 '18 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.