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:
-
Basic Command: To save all logs from a container named
my_containerto a file calledcontainer_logs.txt, use:docker logs my_container > container_logs.txt -
Using
--tail: If you only want to save the last few lines of logs, you can combine the--tailoption:docker logs --tail 100 my_container > container_logs.txt -
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!
