How to save logs to a file?

0147

To save logs from a Docker container to a file, you can redirect the output of the docker logs command to a file using the > operator. Here’s how you can do it:

  1. Basic Command: To save all logs from a container named my_container to a file called container_logs.txt, use:

    docker logs my_container > container_logs.txt
  2. Using --tail: If you only want to save the last few lines of logs, you can combine the --tail option:

    docker logs --tail 100 my_container > container_logs.txt
  3. Appending Logs: If you want to append logs to an existing file instead of overwriting it, use >>:

    docker logs my_container >> container_logs.txt

This will create the file if it doesn't exist or append to it if it does. If you have further questions or need more details, feel free to ask!

0 Comments

no data
Be the first to share your comment!