How to clear Docker container logs based on the timestamp?

I want to automatically clear Docker container logs based on a specific timestamp, such as removing logs older than 30 minutes. However, I am having trouble configuring the compose file to achieve this. Currently, I am only able to control the log file size using the max-size: “” attribute, limiting it to 4KB. Can I accomplish this through a Docker Compose file? If not, how can I achieve this goal? Here’s the Docker Compose file I’ve been using:

version: "3"
services:
  azure-function-app:
    build:
      context: .
      dockerfile: FunctionApp01/Dockerfile
    image: functionapp-nolimit
    container_name: function_app-nolimit
    restart: unless-stopped
    tty: true
    ports:
      - "8081:80"
    logging:
      options:
        max-size: "4k" 

I attempted to clean logs based on their size limit. However, when the size limit is exceeded, all previous logs are deleted, which does not meet my objective. My goal is to delete logs that are older than a specific timestamp.

1 Like

Hi, I need to achieve exactly the same thing. Were you able to find a solution for this? It would be really great if you could share a solution. If not, @Docker Can someone from docker team please help us out here please?

When looking at the options of the logging drivers (doc), it does not seem available natively.