Enable Docker garbage collection

Enable Docker garbage collection

To avoid unused Docker images and volumes consuming the entire disk space, you can enable a clean-up cron job for old StackLight LMA containers and volumes. By default, the cron job runs daily at 6:00 a.m. and cleans stopped StackLight LMA images and containers that are older than one week.

To enable Docker garbage collection:

  1. Open your Git project repository with the Reclass model on the cluster level.

  2. In classes/cluster/<cluster_name>/stacklight/server.yml, specify the following parameter:

    _param:
      docker_garbage_collection_enabled: true
    
  3. Optional. To change the default parameters, use:

    linux:
      system:
        cron:
          user:
            root:
              enabled: true
        job:
          docker_garbage_collection:
            command: docker system prune -f --filter until=$(date +%s -d "1 week ago")
            enabled: ${_param:docker_garbage_collection_enabled}
            user: root
            hour: 6
            minute: 0
    
  4. Log in to the Salt Master node.

  5. Apply the following state:

    salt -C 'I@docker:swarm' state.sls linux.system.cron