Jenkins pipeline to clean up stale images and containers in docker swarm mode

I have set up docker swarm, having 8 nodes in total, 5 workers and 3 managers. I am using Jenkins pipeline to run images through docker stack command. Setup is working fine and Jenkins is able to deploy/run the docker images successfully.
However, I see there are some stale containers or images left in the node and thus, eating the disk space. So, to avoid this, I am manually running below commands :

1. docker info -> this displays stopped containers and all images.
2. docker container prune -f   -> this removes all the stopped and unused containers.
3. docker system prune -a -f   -> this cleans up all the stale images.

I run all the above commands in sequence on all nodes for all environment. Now, I want to automate it through Jenkins pipeline, that would run daily once on all nodes of that docker swarm and cleans up the stale images and containers.
What would be the best approach. Please suggest.
BTW, I am new to docker eco system.

Source: StackOverflow